Reputation: 500
If I have a diagonal matrix with diagonal 100Kx1 and how can I to get its pseudo inverse? I won't be able to diagonalise the matrix and then get the inverse like I would do for small matrix so this won't work
np.linalg.pinv(np.diag(D))
Upvotes: 1
Views: 1322
Reputation: 53039
Just take the reciprocals of the nonzero elements. You can check with a smaller diagonal matrix that this is what pinv
does.
Upvotes: 2
Reputation: 1138
Suppose you have a vector of 100K x 1 named as A:
A = np.arange(100000) # will create a vector of 100k x 1
diagnoal_matrix = np.diag(A)
Then, you can find pseudo inverse of diagonal matrix as following:
np.linalg.pinv(diagnoal_matrix)
Sample code will look like:
import numpy as np
A = np.arange(100000)
diagnoal_matrix = np.diag(A)
B = np.linalg.pinv(diagnoal_matrix)
print B
It will print the output as following:
[[ 0 0 0 ..., 0 0 0]
[ 0 1 0 ..., 0 0 0]
[ 0 0 2 ..., 0 0 0]
...,
[ 0 0 0 ..., 99997 0 0]
[ 0 0 0 ..., 0 99998 0]
[ 0 0 0 ..., 0 0 99999]]
Hope it helps!
Upvotes: -1