I am new to programming. In my latest Python 2.7 project I encountered the following:
RuntimeWarning: overflow encountered in long_scalars
Could someone please elaborate what this means and what I could do to fix that?
The code runs through, but I’m not sure if it is a good idea to just ignore the warning.
It happens during an append process like:
SomeList.append(VeryLongFormula)
Here’s an example which issues the same warning:
yields
In the example above it happens because
ais of dtypeint32, and the maximim value storable in anint32is 2**31-1. Since10**10 > 2**32-1, the exponentiation results in a number that is bigger than that which can be stored in anint32.Note that you can not rely on
np.seterr(all='warn')to catch all overflowerrors in numpy. For example, on 32-bit NumPy
while on 64-bit NumPy:
Both fail without any warning, although it is also due to an overflow error. The correct answer is that 21! equals
According to numpy developer, Robert Kern,
So the burden is on you to choose appropriate
dtypesso that no operation overflows.