[Numpy-discussion] Vectorize or rewrite function to work with array inputs?
ben.root at ou.edu
Tue Feb 1 14:53:36 EST 2011
On Tue, Feb 1, 2011 at 1:30 PM, John Salvatier <jsalvati at u.washington.edu>wrote:
> Have you thought about using cython to work with the numpy C-API (
> http://wiki.cython.org/tutorials/numpy#UsingtheNumpyCAPI)? This will be
> fast, simple (you can mix and match Python and Cython).
> As for your specific issue: you can simply cast to all the inputs to numpy
> arrays (using asarray
> http://docs.scipy.org/doc/numpy/reference/generated/numpy.asarray.html) to
> deal with scalars. This will make sure they get broadcast correctly.
Don't use "asarray" blindly! Using asarray causes masked_arrays to become
regular arrays. If all of the operations in your function are vectorized
already, then you are causing your function to unnecessarially break support
for subclassed arrays like masked_arrays.
Use asanyarray() by default unless it has to be asarray().
Sorry for my rant. I just love masked arrays too much...
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion