Skip to content

Instantly share code, notes, and snippets.

@floringogianu
Forked from fish830617/null.py
Created December 8, 2017 15:53
Show Gist options
  • Save floringogianu/6e94b3da59fbc1287977696daf5e2ead to your computer and use it in GitHub Desktop.
Save floringogianu/6e94b3da59fbc1287977696daf5e2ead 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