[Numpy-discussion] None as missing value

Sven Schreiber svetosch at gmx.net
Mon Jul 3 14:01:24 CDT 2006


Pierre GM schrieb:
>> I was also a bit surprised at the following behavior:
>>>> a = numpy.asarray([1,1])
>>>> a
> array([1, 1])
>>>> a[0]=numpy.nan
>>>> a
> array([0, 1])
> 
> Seems to affect only the int_ arrays:
> 
>>>> a = numpy.asarray([1,1], dtype=float_)
>>>> a
> array([1., 1.])
>>>> a[0]=numpy.nan
>>>> a
> array([        nan,  1.        ])
> 

Sure it works with floats. The question is, should there maybe be an
error if the type of the assigned value doesn't match the dtype of the
array, instead of silently doing something unexpected?
Consider the following (with still the same *integer* array a from my
post above):

>>> a[0]=0.1
>>> a
array([0, 1])
>>> a[0]='0'
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
TypeError: an integer is required

This TypeError makes a lot of sense, but why does it only react to
strings, not to floats?

Cheers,
Sven






More information about the Numpy-discussion mailing list