I have a multi-variable function and i would like to use the map() function with it.
Example:
def f1(a, b, c):
return a+b+c
map(f1, [[1,2,3],[4,5,6],[7,8,9]])
To do this in pmap() , just create a list out of x and y . If you only have two input vectors, though, use map2() . If we want to apply min() to parallel elements of three vectors, we'll need to use pmap() . z is a third vector.
You can pass as many iterable as you like to map() function in Python.
map() takes two arguments at most. The first parameter is which function to apply to each element. This is a required parameter. The second parameter is optional and is provided with the function to be used as the this keyword.
The map function takes two arguments: an iterable and a function , and applies the function to each element of the iterable.
itertools.starmap
made for this:
import itertools
def func1(a, b, c):
return a+b+c
print list(itertools.starmap(func1, [[1,2,3],[4,5,6],[7,8,9]]))
Output:
[6, 15, 24]
You can't. Use a wrapper.
def func1(a, b, c):
return a+b+c
map((lambda x: func1(*x)), [[1,2,3],[4,5,6],[7,8,9]])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With