I have the following simple codes for the sum of two vectors.
However, I get the wrong results when I use NumPy.
The results of the codes is as follows:
In [12]: %run -i test.py
The last 2 elements of the sum [7980015996L, 7992002000L]
The last 2 elements of the sum [-609918596 -597932592]
It's not a long integer, Why?
import numpy as np
def numpysum(n):
a = np.arange(n) ** 2
b = np.arange(n) ** 3
c = a + b
return c
def pythonsum(n):
a = range(n)
b = range(n)
c = []
for i in range(len(a)):
a[i] = i ** 2
b[i] = i ** 3
c.append(a[i] + b[i])
return c
size = 2000
c = pythonsum(size)
print "The last 2 elements of the sum", c[-2:]
c = numpysum(size)
print "The last 2 elements of the sum", c[-2:]