[Numpy-discussion] dtype and array creation

Pauli Virtanen pav at iki.fi
Thu May 20 18:28:42 EDT 2010


Thu, 20 May 2010 13:04:11 -0700, Keith Goodman wrote:
> Why do the follow expressions give different dtype?
> 
>>> np.array([1, 2, 3], dtype=str)
> array(['1', '2', '3'],
>       dtype='|S1')
>>> np.array(np.array([1, 2, 3]), dtype=str)
> array(['1', '2', '3'],
>       dtype='|S8')

Scalars seem to be handled specially. Anyway, automatic determination of 
the string size is a bit dangerous to rely on with non-strings in the 
array:

>>> np.array([np.array(12345)], dtype=str)
array(['1234'], 
      dtype='|S4')

When I looked at this the last time, it wasn't completely obvious how to 
make this to do something more sensible.

-- 
Pauli Virtanen




More information about the NumPy-Discussion mailing list