[Numpy-discussion] use of concatenate with subclass of ndarray
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".
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
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion