[Numpy-discussion] use of concatenate with subclass of ndarray
Pierre GM
pgmdevlist@gmail....
Thu Mar 29 12:36:58 CDT 2007
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 ?
More information about the Numpy-discussion
mailing list