Skip to content

Instantly share code, notes, and snippets.

View fish830617's full-sized avatar

Chia-Yu Fang fish830617

  • Taipei, Taiwan
View GitHub Profile
@fish830617
fish830617 / null.py
Created January 5, 2016 16:01
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()