0% found this document useful (0 votes)
23 views4 pages

Introduction To Vectors and Matrices Using Python

The document introduces scalars, vectors, matrices and tensors. It discusses creating vectors and matrices in NumPy, including using the array() method and passing multi-dimensional lists. It also covers transposing matrices by using the T attribute or transpose() method and how this switches the row and column axes.

Uploaded by

kaanya786
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views4 pages

Introduction To Vectors and Matrices Using Python

The document introduces scalars, vectors, matrices and tensors. It discusses creating vectors and matrices in NumPy, including using the array() method and passing multi-dimensional lists. It also covers transposing matrices by using the T attribute or transpose() method and how this switches the row and column axes.

Uploaded by

kaanya786
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Introduction to Vectors and Matrices using Python

Scalar: Any single numerical value is a scalar as shown in the image


above. It is simply denoted by lowercase and italics. For example: n
Vector: An array of numbers(data) is a vector. You can assume a
column in a dataset to be a feature vector.

A vector is conventionally denoted by a lowercase, italics and bold type


variable(feature) name. For example: x

Matrix: A matrix is a 2-D array of shape (m×n) with m rows and n


columns.

A matrix with m rows and n columns


Each element can be reached via its row and column and is denoted by
a subscript. For example, A₁,₁ returns the element at 1st row and 1st
column.

A matrix is denoted by uppercase, italics, and bold variable name. For


example: A

Tensor: Generally, an n-dimensional array where n>2 is called a


Tensor. But a matrix or a vector is also a valid tensor.

Creating vectors and matrices using NumPy

Since a vector is an array and NumPy has various methods of creating


an array. Firstly, install NumPy and import it in
import numpy as np

And then creating an array requires you to use array() method from
the library:

You can then check the shape of the array using the shape attribute:
Creating a matrix is again very simple, you just have to pass a 2D list to
the array method:

Transposing a matrix(2D array)


and coding them

Transposing a matrix is becomes a very


important topic as it further contributes to calculating the inverse of a
matrix and other data manipulation where you want to mirror the axes
of your dataframe.

Transposing a matrix converts a row vector to a column vector and


vice-versa, it is denoted by the superscript T:

Here is what a square matrix(identical number of rows and columns)


looks like after transposition with interchanged axes:
Subsequent Code for Transposition:

There are 2 ways to transpose a matrix, you can either use the T
attribute or simply use the transpose method:

Using the T attribute

We can also check for the changed shape of the matrix(2D array):

You might also like