Message Boards Message Boards

3 Replies
4 Total Likes
View groups...
Share this post:

I need somefunction[{f,g,h},{1,2,3}] => {f[1],g[2],h[3]}

Posted 9 years ago

I need somefunction[{f,g,h},{1,2,3}] => {f[1],g[2],h[3]}

I would call it mapus and this works, but is a bit longish

mapus[functions, data] := Table[Apply[functions[[i]], {data[[i]]}], {i, 1, Length[functions]}]; Including the Blanks that are not shown here. You need the curly brackets around data because Apply will not work on Atomic expressions.

Anybody knows how to do this?

POSTED BY: joris verrips
3 Replies
Posted 9 years ago

Hi Ilian,

Thanks a lot man, just what I need!


POSTED BY: joris verrips
In[3]:= MapThread[Compose, {{f, g, h}, {1, 2, 3}}]

Out[3]= {f[1], g[2], h[3]}

See this thread for alternative ways.

POSTED BY: Ilian Gachevski

Maybe this will work?

k[n_, m_] := n[[#]] @ m[[#]] & /@ Range[Length[n]]


k[{f, g, h}, {1, 2, 3}]
{f[1], g[2], h[3]}
POSTED BY: Priyan Fernando
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract