How to Create a Vector or Matrix in Python?

This recipe helps you Create a Vector or Matrix in Python

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.

Get Closer To Your Dream of Becoming a Data Scientist with 70+ Solved End-to-End ML Projects

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)

 

Explore More Data Science and Machine Learning Projects for Practice. Fast-Track Your Career Transition with ProjectPro

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]]

Download Materials

What Users are saying..

profile image

Abhinav Agarwal

Graduate Student at Northwestern University
linkedin profile url

I come from Northwestern University, which is ranked 9th in the US. Although the high-quality academics at school taught me all the basics I needed, obtaining practical experience was a challenge.... Read More

Relevant Projects

Many-to-One LSTM for Sentiment Analysis and Text Generation
In this LSTM Project , you will build develop a sentiment detection model using many-to-one LSTMs for accurate prediction of sentiment labels in airline text reviews. Additionally, we will also train many-to-one LSTMs on 'Alice's Adventures in Wonderland' to generate contextually relevant text.

Stock Price Prediction Project using LSTM and RNN
Learn how to predict stock prices using RNN and LSTM models. Understand deep learning concepts and apply them to real-world financial data for accurate forecasting.

Build a Hybrid Recommender System in Python using LightFM
In this Recommender System project, you will build a hybrid recommender system in Python using LightFM .

Tensorflow Transfer Learning Model for Image Classification
Image Classification Project - Build an Image Classification Model on a Dataset of T-Shirt Images for Binary Classification

Learn to Build an End-to-End Machine Learning Pipeline - Part 2
In this Machine Learning Project, you will learn how to build an end-to-end machine learning pipeline for predicting truck delays, incorporating Hopsworks' feature store and Weights and Biases for model experimentation.

Text Classification with Transformers-RoBERTa and XLNet Model
In this machine learning project, you will learn how to load, fine tune and evaluate various transformer models for text classification tasks.

AWS MLOps Project to Deploy a Classification Model [Banking]
In this AWS MLOps project, you will learn how to deploy a classification model using Flask on AWS.

AWS Project to Build and Deploy LSTM Model with Sagemaker
In this AWS Sagemaker Project, you will learn to build a LSTM model on Sagemaker for sales forecasting while analyzing the impact of weather conditions on Sales.

Build a Customer Churn Prediction Model using Decision Trees
Develop a customer churn prediction model using decision tree machine learning algorithms and data science on streaming service data.

AWS MLOps Project for ARCH and GARCH Time Series Models
Build and deploy ARCH and GARCH time series forecasting models in Python on AWS .