Skip to content

Instantly share code, notes, and snippets.

@fish830617
Created January 5, 2016 16:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fish830617/ae6b124a717cf7553dfe to your computer and use it in GitHub Desktop.
Save fish830617/ae6b124a717cf7553dfe to your computer and use it in GitHub Desktop.
Calculate the null space of a matrix by QR factorization.
# null.py
import numpy as np
from scipy.linalg import qr
def qr_null(A, tol=None):
Q, R, P = qr(A.T, mode='full', pivoting=True)
tol = np.max(A) * np.finfo(R.dtype).eps if tol is None else tol
rnk = min(A.shape) - np.abs(np.diag(R))[::-1].searchsorted(tol)
return Q[:, rnk:].conj()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment