# Mapping a function to a Matrix [closed]

I’ve looked up previous answers to this question but haven’t found a suitable answer.

I am trying to Map a function that I defined across a Matrix. The function Maps fine across a 1D array but can’t figure out the syntax to make it work across a matrix.

As an example, I have the following functions defined…

allanVar[ylist_, n_] := 1/2 Mean[(ListCorrelate[Append[PadRight[{-1}, n], 1], MovingAverage[ylist, n]])^2]

clusters[Npts_] := Union[ Table [Round[10^((i - 1) Log[10, 1000]/Npts)], {i, 1, Npts + 1}]]

allanData[zlist2_, Npts_] :=  Transpose[{clusters[Npts], 3600*Sqrt[allanVar[zlist2, #]] & /@ clusters[Npts]}];


I create some sample random data in Matrix form

data = Table[0, {3000}, {5}];

Do[data[[All, i]] = RandomVariate[NormalDistribution[0, 0.1], 3000] +
RandomFunction[WienerProcess[0.005, 0.01], {1/100, 30, 1/100},
5]["Path", i][[All, 2]] ;   , {i, 1, 5} ];


I can Map the function allanData to one of columns of my matrix just fine…

ListLogLogPlot[allanData[data[[All, 1]], 20],  Joined -> True]


But trying to map it to the entire matrix gives me Tensor order errors… not quite sure how to make the functions map across the matrix….

ListLogLogPlot[allanData[data, 20]]

-
 Is this what you're after: ListLogLogPlot[allanData[#, 20] & /@ Transpose[data]]? – Michael E2 Mar 14 at 16:24 Have you consulted the documentation for Map yet? Investigate its optional third levelspec argument. – whuber Mar 14 at 16:24 Michael, that’s exactly what I was after… thanks! @whuber. I just looked up the Map documentation…. ugh… had my head buried so far in that I failed to spot that there is a levelspec for Map…. – Pam Mar 14 at 16:28

## closed as too localized by acl, Oleksandr R., Jens, Sjoerd C. de Vries, m_goldbergMar 15 at 13:46

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.