Numarray newbie question
Robert Kern
rkern at ucsd.edu
Tue Mar 29 02:01:11 EST 2005
ChinStrap wrote:
> I know there are probably alternatives for this with the standard
> library, but I think that would kill the speed I get with numarray:
>
> Say I have two 2-dimensional numarrays (x_mat and y_mat, say), and a
> function f(x,y) that I would like to evaluate at every index.
> Basically I want to be able to say f(x_mat,y_mat) and have it return a
> numarray with the same shape and element wise evaluation of f. I know,
> I want a ufunc, but they look scary to write my own. Are there any
> functions that do this? Or is writing ufuncs easier than it seems?
It depends. If you write f(x,y) such that it operates on arrays as a
whole (meaning you can't use if statements, etc.), then it may Just Work.
If you need to do something where you can't express it like that, then
take a look at Scipy's[1] vectorize[2] function.
[1] http://www.scipy.org
[2] http://oliphant.ee.byu.edu:81/scipy_base/vectorize/
--
Robert Kern
rkern at ucsd.edu
"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
More information about the Python-list
mailing list