[Numpy-discussion] ndarray sub-classing and append function

Tom Aldcroft aldcroft@head.cfa.harvard....
Sun Apr 1 10:19:17 CDT 2012


On Sat, Mar 31, 2012 at 2:25 AM, Prashant Saxena <animator333@yahoo.com> wrote:
> Hi,
>
> 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)
>
> Example:
> vary = VectorArray([v1, v2])
> #vary = numpy.append(vary, [v1], axis=0)
> vary.append(v1)
>
> The commented syntax (numpy syntax) is working but "vary.append(v1)" is not
> working.
>
> Any help?

You might try something like below (untested code, just meant as
pointing in the right direction):

self.resize(len(self) + len(v1), refcheck=False)
self[len(self):] = v1

Setting refcheck=False is potentially dangerous since it means other
references to the object might get corrupted.  You should play with
this option, but the alternative is that if there are *any* references
to the object then the append will fail.

- Tom

> Cheers
>
> Prashant
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>


More information about the NumPy-Discussion mailing list