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 computational material science. I write efficient codes for simulating light-matter interactions at atomic scales. I like to develop Physics, DFT and Machine Learning 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.
[wpedon id="7041" align="center"]

One thought on “Matrix Operations in Python using SciPy

  1. Hello Manas Sharma, I am an engineering professor in Brazil, and I really enjoyed your Blog. I am interested in making applications in the robotics area using Python.
    I’m trying to apply concepts from Kinematics theory based on Denavit-Hartenberg using python.
    If you have any applications on this subject and can show it I would appreciate it.


    Cristian Duarte
    [email protected]

Leave a Reply

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