[Numpy-discussion] recarray field names
Erin Sheldon
erin.sheldon at gmail.com
Wed Mar 15 16:15:04 EST 2006
On 3/15/06, Travis Oliphant <oliphant at ee.byu.edu> wrote:
> The dtype object does contain what you want. In fact. It's the fields
> attribute of the dtype object that is a dictionary accessed by field
> name. Thus, to see if a field is a valid field itdentifier,
>
> if name in t.dtype.fields:
>
> would work (well there is a slight problem in that -1 is a special key
> to the dictionary that returns a list of field names ordered by offset
> and so would work also), but if you now that name is already a string,
> then no problem.
Yes, I see, but I think you meant
if name in t.dtype.fields.keys():
which contains the -1 as a key.
In [275]: t.dtype.fields.keys:
Out[275]: ('tag1','tag2',-1)
So, since the last key points to the names, one can also do:
In [279]: t.dtype.fields[-1]
Out[279]: ('tag1', 'tag2')
which is not transparent, but does what you need. For now, I'll probably
just write a simple function to wrap this.
Thanks,
Erin
More information about the NumPy-Discussion
mailing list