# Apply matrix of function to a list and get matrix of lists [duplicate]

Say I have table in the shape of a matrix of the form:

f[x_] = {{1, 1/4 + x/4}, {0, 1/4 + x/4}}


and a list of numbers

list = {1,2,3,4,5}


What is the easiest way to get a matrix of the same shape as above with its elements corresponding to the each function element of f[x_] applied to the list?

The trouble here is that f[x_] involves constant functions so that doing f[list] gives:

In[188]:= f[list]
Out[188]= {{1,{1/2,3/4,1,5/4,3/2}},{0,{1/2,3/4,1,5/4,3/2}}}


(only the non constant elements are evaluated).

On the other hand, doing, f /@ list evaluates f[x_] as a matrix valued function and gives a list of 2 by 2 matrices:

 In[189]:= f/@list
Out[189]= {{{1,1/2},{0,1/2}},{{1,3/4},{0,3/4}},{{1,1},{0,1}},{{1,5/4},{0,5/4}},{{1,3/2},{0,3/2}}}


This is not what I want either.

What I want is

{{{1,1,1,1,1},{1/2,3/4,1,5/4,3/2}},{{0,0,0,0,0},{1/2,3/4,1,5/4,3/2}}}

• good point. Just edited. – jrekier Jan 19 '17 at 11:44
• {{1+0 x, 1/4 + x/4}, {0 x, 1/4 + x/4}}? – Kuba Jan 19 '17 at 11:47
• @Kuba Only if you use SetDelayed – Simon Rochester Jan 19 '17 at 11:48
• After a review of the answers to (129755) I have concluded that this question "already has an answer" there, and I have marked it accordingly. My favorite solution is bienti's: f[x_] := {{1 + 0 x, 1/4 + x/4}, {0 x, 1/4 + x/4}} – Mr.Wizard Jan 19 '17 at 18:37
• I had seen and tested the mentioned other solutions before asking my question. These are not applicable here as these only work for one dimensional arrays. – jrekier Jan 20 '17 at 11:25

f[x_] = {{1, 1/4 + x/4}, {0, 1/4 + x/4}};

Transpose /@ Transpose[f /@ list, {2, 1}]