Using objects in arrays
Sue Giller <sag <at> hydrosphere.com>
2001-12-04 17:28:38 GMT
I am trying to use objects in an array, and still be able to use the
various extra functions offered by multiarray. I am finding that some
of the functions work and some don't. Is it hopeless to try to use
objects in an array and expect <op>.reduce and others to work
properly?
As a simple example, I have a DataPoint object that consists of a
value and flag(s). This object has all the __cmp__, __add_, etc
functions implemented.
I can do MA.average(m), MA.sum(m), MA.add.reduce(m), (they
seem to use __add__) but I can't do MA.minimum.reduce(m) or
MA.maximum.reduce(m).
I can do MA.maximum(m) and MA.minimum(m), but not
MA.maximum(m, 0) or MA.minimum(m, 0)
The values returned by MA.argmax(m) makes no sense (wrong
index?) but is consistent with results from argsort(). MA.argmin(m)
gives an error (I have a __neg__ fn in datapoint)
File "C:\Python21\MA\MA.py", line 1977, in argmin
return Numeric.argmin(d, axis)
File "C:\Python21\Numeric\Numeric.py", line 281, in argmin
a = -array(a, copy=0)
TypeError: bad operand type for unary -
for example:
print m # 3 valid, 1 masked
print MA.maximum(m)
print MA.argmax(m) # gives index to masked value
(Continue reading)