0

NumPy, RuntimeWarning: invalid value encountered in power

Sometimes I get this in a long and confusing algorithms. How can I get more information out if it. For instance the exact line where it goes wrong and what the values are at that time. for instance if I have a function like this:

def func(x):
    for i in range(100):
        " do something with  x , y

And I use the function

test = func(x)
>  NumPy, RuntimeWarning: invalid value encountered in power

How can see the the values of x,y,i at the time of failure?

I have looked at this NumPy, RuntimeWarning: invalid value encountered in power which does not answer my question because it explains how to avoid it but how get the specific information I want to.

EDIT I have tried:

x = np.random.randint(100)
try:
    test = func( x )
except:
    pass

But I don't how to use the pass function to get the desired information? Why is "except: pass" a bad programming practice?

k.dkhk
  • 481
  • 1
  • 11
  • 24
  • Possible duplicate of [NumPy, RuntimeWarning: invalid value encountered in power](https://stackoverflow.com/questions/45384602/numpy-runtimewarning-invalid-value-encountered-in-power) – jjramsey Jul 01 '19 at 15:31

1 Answers1

0

Use try and except and debug:

try:
    test = def(x)
except:
    pass(debug here)
Afik Friedberg
  • 332
  • 2
  • 8