1

I need to do a pseudo-inverse(np.linalg.pinv) for each (6,4) in (5,4,6,4). However, I didn't find the designed module to solve this problem and I don't want to use the inefficient for loop. What should I do with it?

I think this would be a common problem when we are handling some huge size data... But I have no such experience.

Update: My numpy version is 1.13, python 2.7.13. It doesn't support stacks of matrix.

  • In the [docs](https://docs.scipy.org/doc/numpy-1.15.1/reference/generated/numpy.linalg.pinv.html) it is specified that `pinv` works on stacks of matrices. So doing `np.linalg.pinv(a)` should just work – Brenlla Jan 24 '19 at 16:09
  • 1
    Hard to say without actually profiling it, but I guess that the overhead of the for loop will be insignificant compared to the time it takes to do a matrix inverse. – user545424 Jan 24 '19 at 17:01
  • @Brenlla have you actually tested it? I get the error `ValueError: the truth value of an array....` when trying that. – user2699 Jan 24 '19 at 17:19
  • Yes, I have tried `a=np.random.normal(size=(5,4,6,4))` and then `b=np.linalg.pinv(a)`. `b.shape` should return `(5, 4, 4, 6)` and `b[0,0].dot(a[0,0])` (plus rest of the indices) should return identity matrix – Brenlla Jan 24 '19 at 17:24
  • @Brenlla, Thanks, it looks like I ran into a bug in an older versions of numpy. https://github.com/numpy/numpy/pull/8827 – user2699 Jan 24 '19 at 17:25
  • @brenlla My numpy version is 1.13 which doesn't support stacks of matrics and I am not able to upgrade it. Any other ideas? – Michael Sun Jan 25 '19 at 19:15

0 Answers0