[SciPy-user] Vectorize vs Map
Thu Mar 15 12:15:34 CDT 2007
On 3/15/07, Robert Kern <email@example.com> wrote:
> Lorenzo Isella wrote:
> > Dear All,
> > Probably another newbie question: I like quite a lot the vectorize()
> > command which allows me to skip iterations on functions, but the map()
> > command on a list performs a similar task if I am not mistaken.
> > Is there any reason to favour one above the other or is it just a
> > matter of taste?
> vectorize() takes a Python function and turns it into a ufunc. ufuncs do a lot
> more than map() does. They can take multidimensional arrays. n-ary ufuncs can
> take multiple inputs and broadcast them against each other. ufuncs have methods
> like .inner() and .reduce() which are quite powerful.
Mmh, isn't that what 'frompyfunc' does instead? vectorize doesn't
seem to produce a true ufunc. Perhaps I'm just misunderstanding
In : def foo(x):return x
In : vfoo = N.vectorize(foo)
In : vfoo.outer?
Object `vfoo.outer` not found.
In : type vfoo
Out: <class 'numpy.lib.function_base.vectorize'>
In : ufoo = N.frompyfunc(foo,1,1)
In : type ufoo
Out: <type 'numpy.ufunc'>
In : ufoo.outer?
Base Class: <type 'builtin_function_or_method'>
I'm actually not exactly sure why the two do exist, to be honest. I
realize frompyfunc has (probably by necessity) a more complicated API,
but it does return a true ufunc, which vectorize() doesn't.
More information about the SciPy-user