[Numpy-discussion] Negative values with unsigned data types problems

Francesc Altet faltet at carabos.com
Fri Sep 29 06:44:34 CDT 2006


I'm writing this here because the numpy Trac seems down:


Trac detected an internal error: The Trac Environment needs to be upgraded. 
Run trac-admin /home/scipy/trac/numpy upgrade"

Well, it seems that there are inconsistencies on creating arrays coming from 
negative values using unsigned integers:

In [41]: numpy.asarray([-1], dtype='uint8')
Out[41]: array([255], dtype=uint8)

In [42]: numpy.asarray([-1], dtype='uint16')
Out[42]: array([65535], dtype=uint16)

until here it's fine, but:

In [43]: numpy.asarray([-1], dtype='uint32')
<type 'exceptions.TypeError'>             Traceback (most recent call last)

/home/faltet/python.nobackup/numpy/<ipython console> in <module>()

/usr/local/lib/python2.5/site-packages/numpy/core/numeric.py in asarray(a, 
dtype, order)
    129     are converted to base class ndarray.
    130     """
--> 131     return array(a, dtype, copy=False, order=order)
    133 def asanyarray(a, dtype=None, order=None):

<type 'exceptions.TypeError'>: long() argument must be a string or a number, 
not 'list'

and the same happens with 'uint64'.

My numpy version is 1.0.dev3216


>0,0<   Francesc Altet     http://www.carabos.com/
V   V   Cárabos Coop. V.   Enjoy Data

More information about the Numpy-discussion mailing list