[Numpy-discussion] coercion for array-like objects for ufuncs

Chris Myers myers at tc.cornell.edu
Wed Sep 5 11:39:01 EDT 2001

I have a Python object that contains a NumPy array (among other
things), and I'd like it to behave like an array in certain
circumstances.  (For example, I can define __getitem__ on the class so
that the underlying NumPy array is indexed.)

I'd like to be able to act on such an object with a ufunc, but am
stymied.  For example, if y is an instance of this array-like class of
mine, then I get a type error if I try a reduction on it:

>>> Numeric.minimum.reduce(y)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: function not supported for these types, and can't coerce to supported types

Is there a way I can effect this coercion?  I guess I'd prefer not to
have to inherit from UserArray.



Chris Myers 
Cornell Theory Center
636 Rhodes Hall              email: myers at tc.cornell.edu
Cornell University           phone: (607) 255-5894 / fax: (607) 254-8888
Ithaca, NY 14853             http://www.tc.cornell.edu/~myers

More information about the NumPy-Discussion mailing list