4
$\begingroup$

I have a function F[x,y] and a list of the form:

{{a1,b1},{a2,b2},{a3,b3},{an,bn}}

Basically, I want to pass the list mentioned above as the argument to the function F and get the output as a list of the form:

{F[a1,b1],F[a2,b2],F[a3,b3],F[an,bn]}

How do I do this?

$\endgroup$
4
$\begingroup$

Apply at Level 1:

F @@@ list

{F[a1, b1], F[a2, b2], F[a3, b3], F[an, bn]}

$\endgroup$
2
$\begingroup$

Try

Map[Apply[F, Sequence[#]] &, {{a1, b1}, {a2, b2}, {a3, b3}}]
$\endgroup$
2
$\begingroup$
MapThread[F,Transpose@lst]

{F[a1, b1], F[a2, b2], F[a3, b3], F[an, bn]}

$\endgroup$
0
$\begingroup$

You can always define you F with the appropriate pattern

f[{x_, y_}] := f[x, y]

f /@ {{a1, b1}, {a2, b2}, {a3, b3}, {an, bn}}
(* {f[a1, b1], f[a2, b2], f[a3, b3], f[an, bn]} *)

a variant to the other answers would be

Apply[f] /@ {{a1, b1}, {a2, b2}, {a3, b3}, {an, bn}}
(* {f[a1, b1], f[a2, b2], f[a3, b3], f[an, bn]} *)
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.