[SciPy-User] Making an array subclass, were all all shape changing operations return a normal array.
Kiyoshi Masui
kiyo at cita.utoronto.ca
Mon Mar 28 12:28:42 EDT 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
rollaxis().
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)
Thanks,
Kiyo
More information about the SciPy-User
mailing list