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 Credit Default | Give Me Some Credit Kaggle
In this data science project, you will predict borrowers chance of defaulting on credit loans by building a credit score prediction model.

Zillow’s Home Value Prediction (Zestimate)
Data Science Project in R -Build a machine learning algorithm to predict the future sale prices of homes.

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.

German Credit Dataset Analysis to Classify Loan Applications
In this data science project, you will work with German credit dataset using classification techniques like Decision Tree, Neural Networks etc to classify loan applications using R.

Forecast Inventory demand using historical sales data in R
In this machine learning project, you will develop a machine learning model to accurately forecast inventory demand based on historical sales data.

Resume parsing with Machine learning - NLP with Python OCR and Spacy
In this machine learning resume parser example we use the popular Spacy NLP python library for OCR and text classification.

Predict Employee Computer Access Needs in Python
Data Science Project in Python- Given his or her job role, predict employee access needs using amazon employee database.

Ecommerce product reviews - Pairwise ranking and sentiment analysis
This project analyzes a dataset containing ecommerce product reviews. The goal is to use machine learning models to perform sentiment analysis on product reviews and rank them based on relevance. Reviews play a key role in product recommendation systems.

Time Series Forecasting with LSTM Neural Network Python
Deep Learning Project- Learn to apply deep learning paradigm to forecast univariate time series data.

Sequence Classification with LSTM RNN in Python with Keras
In this project, we are going to work on Sequence to Sequence Prediction using IMDB Movie Review Dataset​ using Keras in Python.