[Numpy-discussion] is it safe to change the dtype without rebuilding the array?

Ernest Adrogué eadrogue@gmx....
Fri Jan 1 17:42:10 CST 2010


Hi,

I find myself doing this:

In [244]: x
Out[244]: 
array([[0, 1, 2],
       [3, 4, 5],
       [6, 7, 8]])

In [245]: y=x.copy()

In [251]: y.dtype.char
Out[251]: 'l'

In [252]: dt=np.dtype([('a','l'),('b','l'),('c','l')])

In [254]: y.dtype=dt

Is it okay?
The problem is that it's not easy to rebuild the array.
I tried with:

y.astype(dt)
np.array(y, dt)
np.array(y.tolist(), dt)

None worked.

Bye.

Ernest


More information about the NumPy-Discussion mailing list