Message Boards Message Boards

GROUPS:

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

Posted 9 years ago
4611 Views
|
3 Replies
|
4 Total Likes
|

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!

Joris

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]]

Output:

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
Attachments
Remove
or Discard

Group Abstract Group Abstract