I believe it’s an overflow mistake

Asked

Viewed 87 times

0

I created two arrays as follows

array1=np.arange(1000000)
array2= np.arange(1000000)

and when I did the following operation:

array1*array2

I got that answer:

array([         0,          1,          4, ..., -731379964, -729379967,
   -727379968])

And when I used the np.Multiply() function I got the same answer:

np.multiply(array1,array2)

I’m using the jupyter notebook, I don’t know if it interferes.

  • I settled the question thank you for warning me.

  • Here (https://repl.it/@acwoss/sopt-Question-387036) did not give this problem. That’s all the same code?

  • 1

    Dear Thiago, this is probably because your Python is 32bit, so the architecture does not support large numbers, in the example of @Andersoncarloswoss works because Repl.it probably runs version 64bit.... Here use 32bit, see the result, is the same as Thiago: https://i.stack.Imgur.com/Tkori.png

  • Thank you for the reply.

1 answer

0

This is probably because your Python is 32bit, so the architecture does not support large numbers, in the @Andersoncarloswoss example (https://repl.it/@acwoss/sopt-Question-387036) works because the Repl.it probably runs version 64bit of Python

In my environment (Windows) I use 32bit also, see that the result is the same as what happened with you:

exemplo de limitação do 32bit no Windows

Upshot:

[         0          1          4 ... -733379959 -731379964 -729379967]

An example of the documentation to determine whether your Python is 32bit or 64bit would be running this https://docs.python.org/3/library/platform.html#cross-Platform, example:

import sys

print(sys.maxsize > 2**32)

Show off False is because it is 32bit and not 64bit, so apart from the "real evidence", a test in repl.it with Python3.6: https://repl.it/repls/DarkturquoiseDescriptiveRuntimelibrary

Returned True, soon the code works as expected to be 64bit, follows the result:

exemplo no repl.it em 64bit

Upshot:

[           0            1            4 ... 999994000009 999996000004
999998000001]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.