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

Bruce Southey bsouthey at gmail.com
Mon Sep 14 10:52:32 EDT 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