You are generating integers that are larger than what your platform or default numpy int values can handle, so are overflowing your numbers.
25 to the seventh power requires 33 bits:
>>> (25 ** 7).bit_length()
33
Python's built-in integer type is unbounded, but numpy uses bounded, fixed size integers, and for your numpy setup, the default signed integer type is int32
, so fails to fit this value.
I can reproduce the exact same output if I tell numpy to convert the output to int32
:
>>> np.sum(np.power(range(26), 7)).astype(np.int32)
792709145
but because I have am running MacOS on a 64-bit CPU, numpy uses int64
as the default integer type and so produces the correct result:
>>> np.sum(np.power(range(26), 7))
22267545625
>>> np.sum(np.power(range(26), 7)).dtype
dtype('int64')
792709145
is the integer value represented by the bottom 31 bits:
>>> print(int(format(22267545625, 'b')[-31:], 2))
792709145
On Windows however, the default numpy integer type is int32 because even on 64-bit hardware Windows defines C long int as a 32-bit value.
You should tell numpy to create an array of int64 values here:
np.sum(np.power(np.arange(26, dtype=np.int64), 7))