Possible Duplicate:
How do I use Map for a function with two arguments?
If I have a function:
F[x_,y_,z_]:=x*y*z
and I want to call it with several different x values using Map
(and y and z fixed), is there a way to do that with a one-liner?
That is, for these x values
xVals = {1,2,3,4}
I want to somehow get:
{F[1,10,100], F[2,10,100], F[3,10,100],F[4,10,100]}
If I can do it with Map, it would be great, because I have many cores and want to speed this up with the parallelized Map.
Answer
You may use map with a pure function:
f[#,10,100]& /@ xVals
{f[1, 10, 100], f[2, 10, 100], f[3, 10, 100], f[4, 10, 100]}
Table will also work:
Table[f[x, 10, 100], {x, xVals}]
{f[1, 10, 100], f[2, 10, 100], f[3, 10, 100], f[4, 10, 100]}
Multiple iterator form:
Table[f[x, y, 100], {x, {1, 2, 3, 4}}, {y, {5, 6, 7, 8}}]
Comments
Post a Comment