[Numpy-discussion] dtype field renaming

Stéfan van der Walt stefan at sun.ac.za
Wed Apr 8 18:47:18 EDT 2009


2009/4/9 Pierre GM <pgmdevlist at gmail.com>:
>> a.dtype.names = ('c', 'd')
>
> Now that's wicked neat trick ! I love it ! Faster than taking a view
> for sure.
> Note that rename_fields should work also w/ nested fields (not that
> common, true).

Yes, that is slightly more effort:

In [30]: arr = np.array(((2,3),), dtype=[('x',[('a',int),('b',int)])])
In [31]: arr['x'].dtype.names = ('p','q')

No all-in-one solution for renaming all the fields, but if you wanted
to do that a view would probably be the cleanest.

Cheers
Stéfan



More information about the NumPy-Discussion mailing list