[Numpy-discussion] Re: The idiom for supporting matrices and arrays in a function

Robert Kern robert.kern at gmail.com
Wed Mar 1 16:52:32 CST 2006


Bill Baxter wrote:
> The NumPy for Matlab Users's wiki is currently pleading to have someone
> fill in  "/*the idiom for supporting both matrices and arrays in a
> function". 
> * /Does anyone know what this is?

The subclassing functionality is rather new, so I don't know if the proper
idioms have really been discovered. I would suggest converting to arrays using
asarray() right at the beginning of the function. If you want to spit out
matrices/what-have-you out again, then you will need to do some more work. I
would suggest looking at the procedure that ufuncs do with __array_finalize__
and __array_priority__ and creating a pure Python reference implementation that
others could use. It's possible that you would be able to turn it into a decorator.

-- 
Robert Kern
robert.kern at gmail.com

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter





More information about the Numpy-discussion mailing list