[SciPy-User] Making an array subclass, were all all shape changing operations return a normal array.

Kiyoshi Masui kiyo@cita.utoronto...
Mon Mar 28 11:28:42 CDT 2011

Hi all,

I have an array subclass, where some of the extra attributes are only 
valid for the object's original shape.  Is there a way to make sure that 
all array shape changing operations return a normal numpy array instead 
of an instance of my class?  I've already written array_wrap, but this 
doesn't seem to have any effect on operations like mean(), sum() and 

    def __array_wrap__(self, out_arr, context=None) :
        if out_arr.shape == self.shape :
            out = out_arr.view(new_array)
            # Do a bunch of class dependant initialization
            . . .
            return out
        else :
            return sp.asarray(out_arr)



More information about the SciPy-User mailing list