[SciPy-User] determining if structured/rec array

Pierre GM pgmdevlist@gmail....
Sun Mar 21 20:43:33 CDT 2010


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


More information about the SciPy-User mailing list