Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Python sympy | Matrix.nullspace() method

  • Last Updated : 13 Aug, 2019

With the help of sympy.Matrix().nullspace() method, we can find the Nullspace of a Matrix. Matrix().nullspace() returns a list of column vectors that span the nullspace of the matrix.

Syntax: Matrix().nullspace()

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course

Returns: Returns a list of column vectors that span the nullspace of the matrix.



Example #1:




# import sympy 
from sympy import * 
  
M = Matrix([[1, 0, 1, 3], [2, 3, 4, 7], [-1, -3, -3, -4]])
print("Matrix : {} ".format(M))
   
# Use sympy.nullspace() method 
M_nullspace = M.nullspace()  
      
print("Nullspace of a matrix : {}".format(M_nullspace))  

Output:

Matrix : Matrix([[1, 0, 1, 3], [2, 3, 4, 7], [-1, -3, -3, -4]]) 
Nullspace of a matrix : [Matrix([
[  -1],
[-2/3],
[   1],
[   0]]), Matrix([
[  -3],
[-1/3],
[   0],
[   1]])]

Example #2:




# import sympy 
from sympy import * 
  
M = Matrix([[14, 0, 11, 3], [22, 23, 4, 7], [-12, -34, -3, -4]])
print("Matrix : {} ".format(M))
   
# Use sympy.nullspace() method 
M_nullspace = M.nullspace()  
      
print("Nullspace of a matrix : {}".format(M_nullspace)) 

Output:

Matrix : Matrix([[14, 0, 11, 3], [22, 23, 4, 7], [-12, -34, -3, -4]]) 
Nullspace of a matrix : [Matrix([
[-1405/4254],
[   -10/709],
[  314/2127],
[         1]])]



My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!