[SciPy-user] null space of a matrix

Ryan Krauss ryanfedora at comcast.net
Wed Jun 29 14:59:57 CDT 2005

This is a completely trivial addition to Richard's submission, but here 
is the function I am using to implement the null function if anyone 
wants to copy and paste it into there own code:

def null(A, eps=1e-15):
    u, s, vh = scipy.linalg.svd(A)
    null_mask = (s <= eps)
    null_space = scipy.compress(null_mask, vh, axis=0)
    return scipy.transpose(null_space)

(this assumes you have already got an import scipy somewhere in the file)
(It made more sense to me to return column vectors.)


Ryan Krauss wrote:

> Thanks Robert.  This works very well.  You seem to always submit high 
> quality input to the list.
> Ryan
> Robert Kern wrote:
>> Ryan Krauss wrote:
>>> This is probably a Numeric question, but is there an easy way to 
>>> find the null space of a matrix in SciPy?
>> The SVD is one way.
>> u, s, vh = linalg.svd(A)
>> null_mask = (s <= eps)
>> null_space = compress(null_mask, vh, axis=0)
>> The rows in null_space span the null space of A.
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.net
> http://www.scipy.net/mailman/listinfo/scipy-user

More information about the SciPy-user mailing list