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

Ray han

Tech Leader | Stanford / Yale University
linkedin profile url

I think that they are fantastic. I attended Yale and Stanford and have worked at Honeywell,Oracle, and Arthur Andersen(Accenture) in the US. I have taken Big Data and Hadoop,NoSQL, Spark, Hadoop... Read More

Relevant Projects

Learn How to Build a Linear Regression Model in PyTorch
In this Machine Learning Project, you will learn how to build a simple linear regression model in PyTorch to predict the number of days subscribed.

BERT Text Classification using DistilBERT and ALBERT Models
This Project Explains how to perform Text Classification using ALBERT and DistilBERT

Time Series Forecasting Project-Building ARIMA Model in Python
Build a time series ARIMA model in Python to forecast the use of arrival rate density to support staffing decisions at call centres.

Multi-Class Text Classification with Deep Learning using BERT
In this deep learning project, you will implement one of the most popular state of the art Transformer models, BERT for Multi-Class Text Classification

PyTorch Project to Build a LSTM Text Classification Model
In this PyTorch Project you will learn how to build an LSTM Text Classification model for Classifying the Reviews of an App .

Azure Deep Learning-Deploy RNN CNN models for TimeSeries
In this Azure MLOps Project, you will learn to perform docker-based deployment of RNN and CNN Models for Time Series Forecasting on Azure Cloud.

Build a Speech-Text Transcriptor with Nvidia Quartznet Model
In this Deep Learning Project, you will leverage transfer learning from Nvidia QuartzNet pre-trained models to develop a speech-to-text transcriptor.

Isolation Forest Model and LOF for Anomaly Detection in Python
Credit Card Fraud Detection Project - Build an Isolation Forest Model and Local Outlier Factor (LOF) in Python to identify fraudulent credit card transactions.

LLM Project to Build and Fine Tune a Large Language Model
In this LLM project for beginners, you will learn to build a knowledge-grounded chatbot using LLM's and learn how to fine tune it.

Build Deep Autoencoders Model for Anomaly Detection in Python
In this deep learning project , you will build and deploy a deep autoencoders model using Flask.