[SciPy-dev] scipy.stats._chk_asarray

Pierre GM pgmdevlist@gmail....
Wed Jun 3 01:17:56 CDT 2009

On Jun 3, 2009, at 1:09 AM, josef.pktd@gmail.com wrote:
> Given my experience with views, I would prefer to limit them to very
> local usage, e.g. views on transposed arrays don't work,

 >>> m = np.matrix([1,2,3])
 >>> m.T
 >>> m.T.view(np.ndarray)

What case did you have in mind ?

>>> And what is the best way to check whether an array is a plain  
>>> ndarray
>>> and not a subclass instance?
>> Er, why do you want to do that ?
> To get fast track for users that deliver already directly usable data,
> without special type handling. This will be more relevant for
> stats.models to handle recarrays and masked arrays, and ?

Mmh. We'll see.

> If someone gives me this decorator, I will use it, but I don't know
> how to write a decorator that works for all input and output cases,
> and doesn't screw up our documentation system.

Try that.

def keepthetype(func):
     def wrapped(*args, **kwargs):
         first = args[0]
         if isinstance(first, np.ndarray):
             output_type = type(first)
             output_type = np.ndarray
         output = func(*args, **kwargs)
         if isinstance(output, np.ndarray):
             return output.view(output_type)
         return output
     wrapped.__name__ = func.__name__
     wrapped.__dict__ = func.__dict__
     wrapped.__doc__ = func.__doc__
     return wrapped

More information about the Scipy-dev mailing list