[Numpy-discussion] ndarray sub-classing and append function
Sat Mar 31 08:51:00 CDT 2012
It doesn't work because numpy.append(a, ...) doesn't modify the array a
in-place: it returns a copy.
Then in your append method, doing "self = numpy.append(...)" won't have any
effect: in Python such a syntax means the "self" local variable will now
point to the result of numpy.append, but it won't modify the object that
self previously pointed to.
I didn't try it, but it should work with
def append(self, other):
which will call the append method of the parent class numpy.ndarray,
modifying self in-place.
Le 31 mars 2012 02:25, Prashant Saxena <firstname.lastname@example.org> a écrit :
> I am sub-classing numpy.ndarry for vector array representation. The append
> function is like this:
> def append(self, other):
> self = numpy.append(self, [other], axis=0)
> vary = VectorArray([v1, v2])
> #vary = numpy.append(vary, [v1], axis=0)
> The commented syntax (numpy syntax) is working but "vary.append(v1)" is
> not working.
> Any help?
> NumPy-Discussion mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion