[Numpy-discussion] Weird clipping when astype(int) used on large numbers
Fri Oct 17 14:34:39 CDT 2008
This a usual thing in integers conversions. If you transform an
integer like 0x0000FFFF from 16 bits to 8bits, you get 0xFFFF, thus a
negative number. As there are no processor instructions that do
saturations (DSP instructions), the behavior is to be expected.
2008/10/17 Tony S Yu <firstname.lastname@example.org>:
> I ran into this weird behavior with astype(int)
> In : a = np.array(1E13)
> In : a.astype(int)
> Out: 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?
> P.S. In case this is a problem with my install:
> OS X 10.5.5
> Python 2.5.1
> Numpy 1.2.0
> Numpy-discussion mailing list
Information System Engineer, Ph.D.
Blogs: http://matt.eifelle.com and http://blog.developpez.com/?blog=92
More information about the Numpy-discussion