[Numpy-discussion] bug in ma.masked_all()?

Pierre GM pgmdevlist at gmail.com
Tue Dec 2 04:42:21 EST 2008


On Dec 2, 2008, at 4:26 AM, Eric Firing wrote:

> From page 132 in the numpy book:
>
>  The fields dictionary is indexed by keys that are the names of the
> fields. Each entry in the dictionary is a tuple fully describing the
> field: (dtype, offset[,title]). If present, the optional title can
> actually be any object (if it is string or unicode then it will also  
> be
> a key in the fields dictionary, otherwise it’s meta-data).

I should read it more often...

>
> I put the titles in as a sort of additional documentation, and  
> thinking
> that they might be useful for labeling plots;

That's actually quite a good idea...

> but it is rather hard to
> get the titles back out, since they are not directly accessible as an
> attribute, like names.  Probably I should just omit them.


We could perhaps try a function:
def gettitle(dtype, name):
     try:
         field = dtype.fields[name]
     except (TypeError, KeyError):
         return None
     else:
         if len(field) > 2:
             return field[-1]
         return None





More information about the NumPy-Discussion mailing list