[Numpy-discussion] use of concatenate with subclass of ndarray
Bryce Hendrix
bhendrix at enthought.com
Tue Mar 27 20:08:04 EDT 2007
We have a class which is a subclass of ndarray which defines
__array_finalize__ to add an attribute. The class looks something like
this:
class UnitArray(ndarray):
# ...
def __new__(cls, data, dtype=None, copy=True, units=None):
# ...
arr = array(data, dtype=dtype, copy=copy)
res = ndarray.__new__(cls, arr.shape, arr.dtype,buffer=arr)
res.units = units
return res
def __array_finalize__(self, obj):
if (isinstance(obj, UnitArray)):
if hasattr(obj, 'units'):
self.units = obj.units
This works for all the ufuncs I've tried, but the result of concatenate
is missing the units attribute. Is this a bug with concatenate, or
expected behavior?
The real class can be found here:
https://svn.enthought.com/svn/enthought/trunk/src/lib/enthought/numerical_modeling/units/unit_array.py
Bryce
More information about the NumPy-Discussion
mailing list