Singular matrix issue with Numpy

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

4 Answers

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)

0

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

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

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

numpy.linalg.svd numpy.linalg.qr

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like