47

I am trying to multiply a vector(3 by 1) by its transpose(1 by 3). I get a (3 by 3) array but I cannot get its inverse. Any idea why?

import numpy as np

c=array([1, 8, 50])
np.transpose(c[np.newaxis]) * c
array([[   1,    8,   50],
   [   8,   64,  400],
   [  50,  400, 2500]])
np.linalg.inv(np.transpose(c[np.newaxis]) * c)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:\Python26\lib\site-packages\numpy\linalg\linalg.py", line 445, in inv
    return wrap(solve(a, identity(a.shape[0], dtype=a.dtype)))
  File "C:\Python26\lib\site-packages\numpy\linalg\linalg.py", line 328, in solve
    raise LinAlgError, 'Singular matrix'
LinAlgError: Singular matrix
1
  • Happens also if you raise the matrix to a negative power.
    – George
    Apr 11, 2018 at 1:05

4 Answers 4

56

The matrix you pasted

[[   1,    8,   50],
 [   8,   64,  400],
 [  50,  400, 2500]]

Has a determinant of zero. This is the definition of a Singular matrix (one for which an inverse does not exist)

http://en.wikipedia.org/wiki/Invertible_matrix

0
41

By definition, by multiplying a 1D vector by its transpose, you've created a singular matrix.

Each row is a linear combination of the first row.

Notice that the second row is just 8x the first row.

Likewise, the third row is 50x the first row.

There's only one independent row in your matrix.

0
24

As it was already mentioned in previous answers, your matrix cannot be inverted, because its determinant is 0. But if you still want to get inverse matrix, you can use np.linalg.pinv, which leverages SVD to approximate initial matrix.

2
-3

Use SVD or QR-decomposition to calculate exact solution in real or complex number fields:

numpy.linalg.svd numpy.linalg.qr

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.