When my friend runs the following code, it gives a RuntimeWarning and returns "inf". However, if I run this same code, it executes without a warning and returns a value.
import numpy as np
total = 0
k = 10**6
arr = np.arange(k, 0, -1)
for i in arr:
total += 1/(i**2)
print(total)
This is her output:
\Anaconda3\lib\site-packages\ipykernel_launcher.py:7: RuntimeWarning: divide by zero encountered in long_scalars
import sys
inf
Replacing np.arange() with the built-in range() solves the problem, and she gets the same output as me.
My question is: what is causing this inconsistency between her output and mine? Additionally, why is she seeing a difference when using np.arange vs range, while for me the output is the same?
We are both using python 3.7.4 via Anaconda, and numpy 1.16.5, on 64-bit Windows 10.
print()to see values forarange()andrange().64-bitPython on both computers?64-bitPython.