[Numpy-discussion] use of concatenate with subclass of ndarray
Bryce Hendrix
bhendrix@enthought....
Thu Mar 29 13:09:38 CDT 2007
I really should widen my tests before proclaiming success... If you
change the default units to "feet", the result of concatenating two
UnitArrays instances with "meters" units is a UnitArray with "feet".
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@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20070329/d8600cc3/attachment.html
More information about the Numpy-discussion
mailing list