Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Python (NumPy, SciPy), finding the null space of a matrix
- A = matrix([
- [2,3,5],
- [-4,2,3]
- ])
- import scipy
- from scipy import linalg, matrixr
- 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)
- Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56)
- [GCC 4.4.5] on linux2
- Type "help", "copyright", "credits" or "license" for more information.
- >>> import scipy
- >>> from scipy import linalg, matrix
- >>> 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)
- ...
- >>> A = matrix([
- ... [2,3,5],
- ... [-4,2,3]
- ... ])
- >>>
- >>> null(A)
- array([], shape=(3, 0), dtype=float64)
- >>>
- A = matrix([[2,3,5],[-4,2,3],[0,0,0]])
- A * null(A)
- >>> [[ 4.02455846e-16]
- >>> [ 1.94289029e-16]
- >>> [ 0.00000000e+00]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement