[Numpy-discussion] ndarray subclassing bug?

Pierre GM pgmdevlist@gmail....
Sun Aug 10 14:09:21 CDT 2008

On Sunday 10 August 2008 14:26:33 Christoph T. Weidemann wrote:
> Why whould tst.sort() show the correct base class and np.sort show
> NoneType as base class for tst?
> I'd appreciate any insights ...

I should take the time to read the question first before answering.

So, according to the numpy book, the .base attribute is "the object the array 
is using for its data buffer, or None if it owns its own memory".

When you create a TestArray, the object points in fact to the subarr variable 
you have defined in your __new__, so your TestArray doesn't own its memory, 
and .base points to subarr.
When you call TestArray.sort, you're not doing anything at all: the .base 
attribute still points to the subarr temporary array you have created, a 
When you call np.sort, you create a copy of your TestArray that ends up owning 
its own memory: its .base becomes None.

I hope I got it right.

So no, you didn't do anything wrong. What behavior were you expecting ?

More information about the Numpy-discussion mailing list