[Numpy-discussion] Bug or feature?

Charles R Harris charlesr.harris at gmail.com
Sat Apr 11 01:09:03 EDT 2009


Ticket #1083 <http://projects.scipy.org/numpy/ticket/1083>,

In [3]: np.array([324938], dtype=np.uint8)
Out[3]: array([74], dtype=uint8)

i.e., 324938 is silently downcast. This is common numpy behavior, but I
wonder if this case shouldn't be an exception. Or in general, if conversion
from out of range python numbers should raise an error. It does for the
int32 case on 32 bit machines:

In [27]: np.array([2**32 - 1], dtype=np.uint32)
Out[27]: array([4294967295], dtype=uint32)

In [28]: np.array([2**32], dtype=np.uint32)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)

/home/charris/<ipython console> in <module>()

ValueError: setting an array element with a sequence.


Although the error message seems singularly inappropriate.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20090410/839fdff5/attachment.html>


More information about the NumPy-Discussion mailing list