How to Create a Vector or Matrix in Python?
DATA MUNGING DATA CLEANING PYTHON MACHINE LEARNING RECIPES PANDAS CHEATSHEET     ALL TAGS

How to Create a Vector or Matrix in Python?

How to Create a Vector or Matrix in Python?

This recipe helps you Create a Vector or Matrix in Python

0

Recipe Objective

Have you ever tried to create a transpose of a vector or matrix? Is"nt it very easy to calculate manually but if you have to calcuate transpose of many matrises then it may not be possible to do it manually.

So this is the recipe on how we can Create & Transpose a Vector or Matrix.

Step 1 - Import the library

import numpy as np

We have only imported numpy which is needed.

Step 2 - Setting up the Vector and Matrix

We have created a vector and matrix using array and we will find transpose of it. vector = np.array([10, 20, 30, 40, 50, 60]) print("Original Vector: ", vector) matrix = np.array([[11, 22, 33], [44, 55, 66], [77, 88, 99]]) print("Original Matrix: ", matrix)

Step 3 - Calculating transpose of vector and matrix

We can make transpose of vector and matrix by using T function, i.e. applying .T after the vector and matrix. V = vector.T print("Transpose Vector: ", V) M = matrix.T print("Transpose Matrix: ", M) So the output comes as

Original Vector: 
 [10 20 30 40 50 60]

Original Matrix: 
 [[11 22 33]
 [44 55 66]
 [77 88 99]]
Transpose Vector: 
 [10 20 30 40 50 60]
Transpose Matrix: 
 [[11 44 77]
 [22 55 88]
 [33 66 99]]

Relevant Projects

Predict Churn for a Telecom company using Logistic Regression
Machine Learning Project in R- Predict the customer churn of telecom sector and find out the key drivers that lead to churn. Learn how the logistic regression model using R can be used to identify the customer churn in telecom dataset.

Data Science Project in Python on BigMart Sales Prediction
The goal of this data science project is to build a predictive model and find out the sales of each product at a given Big Mart store.

Demand prediction of driver availability using multistep time series analysis
In this supervised learning machine learning project, you will predict the availability of a driver in a specific area by using multi step time series analysis.

Machine Learning project for Retail Price Optimization
In this machine learning pricing project, we implement a retail price optimization algorithm using regression trees. This is one of the first steps to building a dynamic pricing model.

Build a Collaborative Filtering Recommender System in Python
Use the Amazon Reviews/Ratings dataset of 2 Million records to build a recommender system using memory-based collaborative filtering in Python.

Solving Multiple Classification use cases Using H2O
In this project, we are going to talk about H2O and functionality in terms of building Machine Learning models.

Customer Market Basket Analysis using Apriori and Fpgrowth algorithms
In this data science project, you will learn how to perform market basket analysis with the application of Apriori and FP growth algorithms based on the concept of association rule learning.

Loan Eligibility Prediction using Gradient Boosting Classifier
This data science in python project predicts if a loan should be given to an applicant or not. We predict if the customer is eligible for loan based on several factors like credit score and past history.

Choosing the right Time Series Forecasting Methods
There are different time series forecasting methods to forecast stock price, demand etc. In this machine learning project, you will learn to determine which forecasting method to be used when and how to apply with time series forecasting example.

PySpark Tutorial - Learn to use Apache Spark with Python
PySpark Project-Get a handle on using Python with Spark through this hands-on data processing spark python tutorial.