[Numpy-discussion] Apply a function to an array elementwise

Elfnor elfnor@gmail....
Wed Dec 3 18:06:28 CST 2008


I want to apply a function (myfunc which takes and returns a scalar) to each
element in a multi-dimensioned array (data):

I can do this:

newdata = numpy.array([myfunc(d) for d in data.flat]).reshape(data.shape)

But I'm wondering if there's a faster more numpy way. I've looked at the
vectorize function but can't work it out.

thanks Eleanor
View this message in context: http://www.nabble.com/Apply-a-function-to-an-array-elementwise-tp20823768p20823768.html
Sent from the Numpy-discussion mailing list archive at Nabble.com.

More information about the Numpy-discussion mailing list