[Numpy-discussion] Suggestion for recarray.view

Travis E. Oliphant oliphant@enthought....
Thu Sep 18 22:13:46 CDT 2008

Pierre GM wrote:
> All,
> I'd like to submit the following suggestion for recarray.view, so that it 
> could accept two keywords like standard ndarrays do. 
> As a change in records.py can potentially affect a lot of people (probably 
> more than a change in numpy.ma), I'm not confident enough to commit it.
> Consider that as an attempt of having it peer-reviewed before inclusion. 
> Cheers
> P.
> #---------------
>     def view(self, dtype=None, type=None):
>         if dtype is None:
>             return ndarray.view(self, type)
>         elif type is None:
>             try:
>                 if issubclass(dtype, ndarray):
>                     return ndarray.view(self, dtype)
>             except TypeError:
>                 pass
>             dtype = sb.dtype(dtype)
>             if dtype.fields is None:
>                 return self.__array__().view(dtype)
>             return ndarray.view(self, dtype)
>         else:
>             return ndarray.view(self, dtype, type)
> #---------------
This looks pretty good to me.

+1 for adding it.


More information about the Numpy-discussion mailing list