[Numpy-discussion] How to change the dtype of a structured or record array

Bruce Southey bsouthey@gmail....
Mon Sep 14 09:52:32 CDT 2009


Hi,
I would like to change the dtype of just one field of a structured or 
record array without copying the original array. I can not change the 
creation of the original array because it was created using genfromtxt.

For example,
r=np.rec.array([(1, 1.0), (1, 1.0), (1, 1.0)],dtype=[('foo', int), 
('bar', float)]) # illustrative example
r=r.astype([('foo', int), ('bar', int)]) # works this creates as copy

Is there alternative way to avoid this extra copying?

Thanks
Bruce




More information about the NumPy-Discussion mailing list