adding an attribute to an nd-array

Tim Hochberg tim.hochberg at ieee.org
Thu Oct 19 16:34:57 CDT 2006


Christopher Barker wrote:
> Travis Oliphant wrote:
>   
>> Actually something as simple as
>>
>> class InfoArray(N.ndarray):
>>          pass
>>
>> will allow you to add attributes to InfoArray.
>>     
>
> Well, sure, but how the heck do you initialize it?
>
>  >>> class InfoArray(N.ndarray):
> ...          pass
> ...
>  >>> InfoArray((1,2,3))
> InfoArray([[[  6.61855173e-306,               nan,   4.94708449e+173],
>          [  3.32457336e-309,   1.08825491e+175,   2.12468326e-314]]])
>
> InfoArray(N.array((1,2,3)))
> InfoArray([[[  2.17854722e-305,   1.90979621e-313,   1.90979621e-313],
>          [  1.90979621e-313,   1.90979621e-313,   1.03977794e-312]]])
>
> I, for one, would like a very easy to subclass version of ndarray, maybe 
> one that had a default constructor like numpy.array().
>
>   
Back when I was working on basearray, I had an idea for this. Basically, 
it was to to move the ndarray constructor[1] over to basearray and make 
the ndarray constructor work just like array does now[2]. Thus 
array(args) and ndarray(args) would behave the same[2 again]. For the 
full power/complexity of the current ndarray constructor, you would 
instead use basearray(). I believe (and I did some experiments on this 
at one point), that this would allow straightforward inheritance from 
ndarray. I've been away from this for several months now, so sadly I 
forget many of the details.

-tim




[1] I know, I know, it's really __new__, but it gets used like a 
constructor so I'll call it one for the time being.
[2] Modulo the copy arg which would disappear if I had anything to with it.


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642




More information about the Numpy-discussion mailing list