Numpy, map

Charles Boncelet boncelet at udel.edu
Wed May 3 02:59:18 EDT 2000


Josef Dalcolmo wrote:

> Hello, NumPy Wizards!
>
> I am still missing something equivalent to map()
> When I define a function, it is not always possible to use only ufuncs for
> it. When I then want to apply such a homemade function to an array, I either
> have to loop, or to map and then convert. I wish there was something like
> 'amap()', which takes an arbitrary function and returns an array.
>

So do I.

One trick: If your function can be computed with a look-up table, then
use "take".

>>> lut = []
>>> for i in range(256):
>>>   lut.append(func(i))
>>> b = Numeric.take(lut, a)

It can be much faster than computing the function on each element of a.
(Of course, many functions can't be computed this way.)

    Charlie Boncelet


--
------
Charles Boncelet, University of Delaware,
On sabbatical at ADFA, Canberra Australia,
Home Page: http://www.ece.udel.edu/~boncelet/






More information about the Python-list mailing list