[Numpy-discussion] Weird clipping when astype(int) used on large numbers

Charles R Harris charlesr.harris@gmail....
Fri Oct 17 16:00:30 CDT 2008

On Fri, Oct 17, 2008 at 1:27 PM, Tony S Yu <tonyyu@mit.edu> wrote:

> I ran into this weird behavior with astype(int)
> In [57]: a = np.array(1E13)
> In [58]: a.astype(int)
> Out[58]: array(-2147483648)
> I understand why large numbers need to be clipped when converting to
> int (although I would have expected some sort of warning), but I'm
> puzzled by the negative value. Shouldn't the above code clip the value
> to the max positive int (2147483647)... and maybe issue a warning?

Try more precision:

In [2]: a = np.array(1e13)

In [3]: a.astype(np.int64)
Out[3]: array(10000000000000)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20081017/28321a1d/attachment.html 

More information about the Numpy-discussion mailing list