[Numpy-discussion] use of concatenate with subclass of ndarray

Bryce Hendrix bhendrix at enthought.com
Thu Mar 29 13:47:48 EDT 2007


doh! I followed the example on the Wiki which does not define the class 
attribute in the class scope, but in __new__. Adding the declaration to 
the class scope seems to work.

Thanks,
Bryce

Pierre GM wrote:
> On Thursday 29 March 2007 12:04:51 Bryce Hendrix wrote:
>   
>> I spoke too soon, this code fails with the example you gave:
>>     
>
> mmh, I tried to use the class you linked to last time: the only modifications 
> I gave are listed below
>
> class UnitArray(numpy.ndarray):
>     __array_priority__ = 10.0
>     default_unit = "meters"
>
>     def __array_finalize__(self, obj):
>         self.units = getattr(obj,'units',UnitArray.default_unit)
>
> then I used that for testing:
>     meters = "meters"
>     feet = "feet"
>     unit_ary_1 = UnitArray(numpy.array((1,2,3)), units=meters)
>     unit_ary_2 = UnitArray(numpy.array((1,2,3)), units=meters)
>     
>     unit_ary_3 = UnitArray(numpy.array((1,2,3)), units=feet)
>
>     new_unit_ary = numpy.concatenate([unit_ary_1, unit_ary_2])
>     print new_unit_ary.units
>
> And it seems to work. Could you be a bit more specific ?
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
>   

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20070329/6f3e93cf/attachment.html>


More information about the NumPy-Discussion mailing list