[Numpy-discussion] recarray field names
Travis Oliphant
oliphant at ee.byu.edu
Wed Mar 15 16:02:01 CST 2006
Erin Sheldon wrote:
>On 3/15/06, Perry Greenfield <perry at stsci.edu> wrote:
>
>
>>You are right that this is messy. We would like to change this
>>sometime. But we'd like to complete the transition to numpy first
>>before doing that so it may be some months before we can (and it may
>>not look quite like what you suggest). But your point is very valid.
>>
>>Thanks, Perry
>>
>>
>
>OK, fair enough.
>
>Incidentally, I realized that this attribute
>_coldefs is not part of recarray anyway, but something added by pyfits.
>I see now that the names and the formats with a greater than sign
>concatenated on the front can be extracted from dtype:
>
>In [247]: t.dtype
>Out[247]: [('x', '>f4'), ('y', '>i4')]
>
>I could write my own function to extract what I need, but I thought I
>would ask: is there already a simpler way? And is there a function to
>compare this '>f4' stuff to the named types such as Float32 ('f')?
>
>
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.
-Travis
More information about the Numpy-discussion
mailing list