I start to learn python from 《Numpy Beginner's Guide》second edition written
by Ivan Idris
now I know what the problem is ,the reason is that Numpy converts 2000 to an
`int32`.When I use code `a=np.arange(2000, dtype='int64')**3 that you taught
me, the calculation is correct thank you all ! Yu
> On Jan 29, 2019, at 12:15 AM, Matti Picus wrote:
>> Perhaps you could suggest they add this explanation (or if it is in our
>> documentation point out where you think would be appropriate) since it seems
>> many people have problems with dtypes and overflow.
arange() is particularly problem
I'm not sure which numpy version you're using (I don't get that using numpy
1.14.3), but the issue is that for some reason the data type (dtype) of the
array is being assumed to be a 4 byte integer or ' wrote:
> From: Yuping Wang
> To: numpy-discussion@python.org
> Cc:
> Bcc:
> Date: Tue, 29 Jan
On Tue, 29 Jan 2019 10:15:00 +0200, Matti Picus wrote:
> 2000*2000*2000 overflows a 32 bit signed integer, so it wraps around to a
> negative value.
I was curious about what happens, bit-wise, in this case. We are dealing
with a signed integer, so I presume of the 33 bits in 2000**3, only 32
are
On 29/1/19 9:22 am, Yuping Wang wrote:
Dear Nmupy developers and users:
I am a new user of Numpy ,I have encountered a question about
Numpy recently, which need your help. The question is below:
I don know why there are negative numbers
can somebody explain to me why these
You are seeing negative numbers because of an overflow beyond 32 bits. Change
the type of your np array to int64 using a = (np.arange(2000) **
3).astype(np.int64) and you won’t see negative numbers. I assume you are
running this code on a 32 bit machine which is why Numpy is defaulting to
int32