SVD question

Robert Kern robert.kern at
Sat Mar 18 03:57:25 CET 2006

smritibhagat at wrote:
> Hi Robert!
> Oh! Its not a homework problem...
> I read the Golub book, it tells me what an orthogonal complement is,
> however, I cannot understand how I can code it.
> I know about svd from numpy's mlab, but I what I want to know is how
> can I compute an orthogonal complement, using SVD or otherwise.

Assuming A is an array with the vectors as columns and has shape (m, n), then
the null space of A (= the orthogonal complement of the vectors assuming that
the set of vectors is linearly independent):

In [231]: A
array([[ 0.,  1.],
       [ 1.,  1.],
       [ 2.,  1.],
       [ 3.,  1.]])

In [232]: m, n = A.shape

In [233]: u, s, vh = numpy.linalg.svd(A)

In [234]: dot(transpose(u[:, n:]), A)
array([[  0.00000000e+00,  -1.11022302e-16],
       [ -1.42247325e-16,  -5.65519853e-16]])

In [235]: ortho_complement = u[:, n:]

In [236]: ortho_complement
array([[-0.38578674, -0.38880405],
       [ 0.22458489,  0.80595386],
       [ 0.70819044, -0.44549557],
       [-0.54698859,  0.02834576]])

Robert Kern
robert.kern at

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

More information about the Python-list mailing list