Matrix Operations in Python using SciPy

In this blog post, I demonstrate a Python code, that shows how to perform various matrix operations such as:
1. Defining a matrix,
2. Adding matrices
3. Multiplying two matrices,
4. Transposing a Matrix
5. Determinant of a matrix,
6. Inverse of a matrix,
7. Eigenvalues and eigenvectors of a matrix,

using the SciPy package and the lining module within it.

The documentation for SciPy lining is:

The code is pretty much self-explanatory, although you can also watch the YouTube video below it where I walkthrough the code.


import numpy as np 
from scipy import linalg as lg

#Defining a matrix A
A = np.array([  [1, 2] , [3, 4]  ])

#Defining matrix B
B = np.array([ [6, 1], [5, 1] ])

sum1 = A+B
diff = A-B
prod =
transpose = A.T
determinantB = lg.det(B)
#Inverse (if non-singular)
inverse = lg.inv(B)
#Eigenvalues, Eigenvectors of square matrix
values, vectors = lg.eig(B)
#Print Matrix A
#Print Matrix B
#Print A+B
#Print A-B
#Print A*B
#Print A'
#Print det(B)




YouTube Tutorial

PhD researcher at Friedrich-Schiller University Jena, Germany. I'm a physicist specializing in theoretical, computational and experimental condensed matter physics. I like to develop Physics related apps and softwares from time to time. Can code in most of the popular languages. Like to share my knowledge in Physics and applications using this Blog and a YouTube channel.

Leave a Reply

Your email address will not be published. Required fields are marked *