2
$\begingroup$

This question already has an answer here:

I have two lists of equal lengths but for my task I will use 3-element lists , namely {x,y,z} and {f,g,h}. The first contains variables and the second functions.

I want to produce {f[x],g[y],h[z]} with input the above lists in as many ways as possible.

Until now I have devised the following ones:

Inner[#1[#2]&,{f,g,h},{x,y,z},List]

and

MapThread[#1[#2]&,{{f,g,h},{x,y,z}}]

As pointed out , there is a very similar thread at wolfram's community.

If I come up with more solutions I will add them here.

Update

I am updating with the one-liners. In Wolfram's Community forum there are also solutions changing Attributes or using Append but I will omit them here.

MapThread[#1[#2]&,{{f,g,h},{x,y,z}}]

Inner[#1[#2]&,{f,g,h},{x,y,z},List]

Diagonal[Through/@Distribute[{f,g,h}[{x,y,z}],List]

MapThread[Compose,{{f,g,h},{x,y,z}}]

Apply[List,{f,g,h}.{x,y,z}/.Times->(Operate[##1,0]&)] and Apply[List,{f,g,h}.{x,y,z}/.Times->(#1[#2]&)] work only because f,g,h are before x,y,z in alphabetical order as very well pointed out by @andre

 Apply[Compose,Thread[{{f,g,h},{x,y,z}}],{1}]

 (#1[[1]][#1[[2]]]&)/@Transpose[{{f,g,h},{x,y,z}}]
$\endgroup$

marked as duplicate by Mr.Wizard Dec 12 '13 at 21:23

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 3
    $\begingroup$ Distributing a list of heads over a list of arguments $\endgroup$ – ssch Dec 12 '13 at 19:49
  • $\begingroup$ Thanks @ssch this is exactly what I was searching. $\endgroup$ – tchronis Dec 12 '13 at 19:52
  • $\begingroup$ I would not delete - as entry point for the community thread it should be useful. $\endgroup$ – Yves Klett Dec 12 '13 at 19:58
  • $\begingroup$ Ok , thank you @Yves Klett , I will edit the post and if any more solutions come to my attention (beside that of the community's) i will add them. $\endgroup$ – tchronis Dec 12 '13 at 20:02
  • 1
    $\begingroup$ Apply[List, {f, g, h}.{x, y, z} /. Times -> (Operate[##1, 0] &)] works only because f,g,h are before x,y,z in alphabetical order. The problem is the commutativity of Times. For example Apply[List, {f, g, h}.{a, y, z} /. Times -> (Operate[##1, 0] &)]doesn't work. $\endgroup$ – andre314 Dec 12 '13 at 20:32

Browse other questions tagged or ask your own question.