Skip to content

BUG: numpy.linalg.inv returning different values on consecutive calls with some nan elements #20233

@leobiec

Description

@leobiec

Describe the issue:

I have a calculus of an inverse matrix in the middle of my code (some module developed by me) and debugging I found that numpy could not provide and inverse matrix. Also, only a few elements where reported as nan (don´t know if this is as expected or the complete matrix should be nan).

Anyway, if I stop the calculus at this point, and call again the inverse, it does provide an inverse matrix. Seems that something is changed in the numpy module in the first call, and not restored, so the next calls I have a different output.

The code I provide as an example does not work stand alone. I tried executing at the beginning of my complete code and it does provide the same result. So, something in my code previously has an effect on how numpy gets configured to the place where it does fail.

Sorry I cant provide the complete code and libraries. Don’t know how can I provide some stand alone code to reproduce this failure. Can I help the debugging of this issue in an other way?

Regards

Leonardo

Reproduce the code example:

a = np.array([[ 1.06902137e-08+1.03397577e-25j, -8.29800043e-09+1.46316136e-09j,
         1.06153905e-08+7.03229683e-10j, -8.26255952e-09+1.45691217e-09j],
       [-8.29800043e-09-1.46316136e-09j,  1.06902137e-08+0.00000000e+00j,
        -8.26255952e-09-1.45691217e-09j,  1.06153905e-08-7.03229683e-10j],
       [ 1.06153905e-08-7.03229683e-10j, -8.26255952e-09+1.45691217e-09j,
         1.06902137e-08+7.23783036e-25j, -8.29800043e-09+1.46316136e-09j],
       [-8.26255952e-09-1.45691217e-09j,  1.06153905e-08+7.03229683e-10j,
        -8.29800043e-09-1.46316136e-09j,  1.06902137e-08-7.23783036e-25j]])
print(np.linalg.inv(a))
print(np.linalg.inv(a))

[[            nan           +nanj -3.75115133e+11-5.40693281e+10j
  -3.79340139e+11-1.19099169e+11j  3.72964747e+11-6.57637077e+10j]
 [            nan           +nanj  3.98070598e+11-1.64825002e-01j
   3.72964747e+11+6.57637077e+10j -3.79340139e+11+1.19099169e+11j]
 [            nan           +nanj  3.72964747e+11-6.57637077e+10j
   3.98070588e+11-1.88123676e-01j -3.34000150e+11+1.79105405e+11j]
 [            nan+6.57637077e+10j -3.79340139e+11-1.19099169e+11j
  -3.34000150e+11-1.79105405e+11j  3.98070588e+11-1.64492045e-01j]]
[[ 3.98070598e+11-1.88316777e-01j -3.75115133e+11-5.40693281e+10j
  -3.79340139e+11-1.19099169e+11j  3.72964747e+11-6.57637077e+10j]
 [-3.75115133e+11+5.40693281e+10j  3.98070598e+11-1.64825002e-01j
   3.72964747e+11+6.57637077e+10j -3.79340139e+11+1.19099169e+11j]
 [-3.79340139e+11+1.19099169e+11j  3.72964747e+11-6.57637077e+10j
   3.98070588e+11-1.88123676e-01j -3.34000150e+11+1.79105405e+11j]
 [ 3.72964747e+11+6.57637077e+10j -3.79340139e+11-1.19099169e+11j
  -3.34000150e+11-1.79105405e+11j  3.98070588e+11-1.64492045e-01j]]

Error message:

No response

NumPy/Python version information:

numpy version 1.20.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy