Tag Info

Hot answers tagged

11

This perhaps: Function[{a, b}, a[#]/b[#] &] @@@ {{a, b}, {c, d}, {e, f}} (* Out: {a[#1]/b[#1] &, c[#1]/d[#1] &, e[#1]/f[#1] &} *) Mr.Wizard's way of writing it (see comment) looks like this in the frontend:


5

You can almost always turn to replacement patterns when you need to transform expressions: Cases[ {{a, b}, {c, d}, {e, f}}, {x_, y_} :> (x[#]/y[#] &) ] {a[#1]/b[#1] &, c[#1]/d[#1] &, e[#1]/f[#1] &} Cases defaults to levelspec {1} so this is safer than using /..


4

Also: With[{a = #1, b = #2}, a[#]/b[#] &] & @@@ {{a, b}, {c, d}, {e, f}} or x[#]/y[#] & /. {x -> #1, y -> #2} & @@@ {{a, b}, {c, d}, {e, f}} (* {a[#1]/b[#1] &, c[#1]/d[#1] &, e[#1]/f[#1] &} *)


2

Also: Transpose[{as, bs}] /. {a_, b_} :> (f[a, b, #] &) (* {f[1, 4, #1] &, f[2, 5, #1] &, f[3, 6, #1] &} *)


2

You're very close to the solution. You already have as = {1, 2, 3} bs = {4, 5, 6} MapThread[g, {as, bs}] (* ==> {g[1, 4], g[2, 5], g[3, 6]} *) Now all you need is g[a_, b_][x_] := f[a, b, x] Or alternatively write Function[{a, b}, f[a, b, #] &] in place of g in MapThread.



Only top voted, non community-wiki answers of a minimum length are eligible