'invalid value encountered in double_scalars' warning, possibly numpy

Viewed 301729

As I run my code I get these warnings, always in groups of four, sporadically. I have tried to locate the source by placing debug messages before and after certain statements to pin-point its origin.

Warning: invalid value encountered in double_scalars
Warning: invalid value encountered in double_scalars
Warning: invalid value encountered in double_scalars
Warning: invalid value encountered in double_scalars

Is this is a Numpy warning, and what is a double scalar?

From Numpy I use

min(), argmin(), mean() and random.randn()

I also use Matplotlib

8 Answers

In my case, I found out it was division by zero.

Whenever you are working with csv imports, try to use df.dropna() to avoid all such warnings or errors.

I encount this while I was calculating np.var(np.array([])). np.var will divide size of the array which is zero in this case.

As soon as you perform an operation with NaN ('not a number'), math.inf, divide by zero etc. you get this warning. Beware that the output number of an operation with NaN etc. also results in NaN. For example:

import math as m
print(1 + m.nan)

has the output

NaN
Related