[SciPy-User] determining if structured/rec array

Skipper Seabold jsseabold@gmail....
Sun Mar 21 21:24:12 CDT 2010

On Sun, Mar 21, 2010 at 9:43 PM, Pierre GM <pgmdevlist@gmail.com> wrote:
> On Mar 21, 2010, at 12:12 PM, Skipper Seabold wrote:
>> Is there anywhere in scipy that works on structured arrays
>> dynamically?  If not, is this a good way to determine if a structured/
>> rec array was given to a function or is there a better/easier way?
>> import numpy as np
>> def isstructarray(X):
>>    """
>>    Returns a bool indicating if X is a structured or recarray.
>>    Parameters
>>    -----------
>>    X : ndarray or subclass
>>    Returns
>>    -------
>>    True or False, indicating if X is a structured or recarray.
>>    """
>>    if X.__class__ is np.recarray or (isinstance(X, np.ndarray) and\
>>            X.dtype.names):
>>        return True
>>    else:
>>        return False
> Meh. As long as dtype.names is not None, you have a structured array (recarrays are by definition structured arrays). Looks like a function that doesn't really do anything...
> -1

Hmm, so that's definitely simpler.  I thought there was a corner case
that returned an error, so I used this if statement, but I wrote this
a while ago and never bothered messing with it since.



More information about the SciPy-User mailing list