Numpy: Invalid value found in true_divide

I have two numpy arrays, and I'm trying to split them into another and at the same time, I want to make sure that records in which the divisor is 0 should simply be replaced with 0.

So, I am doing something like:

log_norm_images = np.where(b_0 > 0, np.divide(diff_images, b_0), 0) 

This gives me a warning about the runtime:

 RuntimeWarning: invalid value encountered in true_divide 

Now I wanted to see what was happening, and I did the following:

 xx = np.isfinite(diff_images) print (xx[xx == False]) xx = np.isfinite(b_0) print (xx[xx == False]) 

However, both of them return empty arrays, which means that all values โ€‹โ€‹in the arrays are finite. So I'm not sure where the invalid value comes from. I assume that checking b_0> 0 in the np.where function will take care of dividing by 0.

The shape of the two arrays (96, 96, 55, 64) and (96, 96, 55, 1)

+6
source share
1 answer

You may have NAN , INF or NINF , somewhere around. Try the following:

 np.isfinite(diff_images).all() np.isfinite(b_0).all() 

If one or both of them returns False , this is probably the cause of the runtime error.

+5
source

Source: https://habr.com/ru/post/980709/


All Articles