Dear all,
I often make use of numpy.vectorize to make programs read more like
the physics equations I write on paper. numpy.vectorize is basically
a wrapper for numpy.frompyfunc. Reading Travis's Scipy Book (mine is
dated Jan 6 2005) kind of suggests to me that it returns a full-
fledged ufunc exactly like built-in ufuncs.
First, is this true? Second, how is the performance? i.e., are my
functions performing approximately as fast as they could be or would
they still gain a great deal of speed by rewriting it in C or some
other compiled python accelerator?
As an aside, I've found the following function decorator to be
helpful for readability, and perhaps others will enjoy it or improve
upon it:
def autovectorized(f):
"""Function decorator to do vectorization only as necessary.
vectorized functions fail for scalar inputs."""
def wrapper(input):
if type(input) == numpy.arraytype:
return numpy.vectorize(f)(input)
return f(input)
return wrapper
For those unfamiliar to the syntactic joys of Python 2.4, you can
then use this as:
@autovectorized
def myOtherwiseScalarFunction(*args):
...
and now the function will work with both numpy arrays and scalars.
Take care,
Nick
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Numpy-discussion mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/numpy-discussion