Suppose I have a 8by6by4by2by2 matrix called m. There is in total 8*6*4 2by2 matrices. I want to map a function over these 2by2 matrices. Each dimension in m contains a 2by2 matrix for some specific parameters. My example code and solution is:

m = RandomReal[{0, 1}, {8, 6, 4, 2, 2}];
m2 = Flatten[m, 2];(* 8*6*4 matrices of size 2by2*)
f[m_] := Total@Eigenvalues[m]
Map[f, m2]

However, then I cannot reconstitute the result in the original order of m. Is there some other way to map over multidimensional matrices?

I have to reconstitute the result of map in order to first average the result over first dimension, 8 here, and then plot the 6by4 matrix in a contour plot.


closed as off-topic by MarcoB, user9660, m_goldberg, Edmund, Karsten 7. May 25 '16 at 12:41

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – MarcoB, Community, m_goldberg, Edmund, Karsten 7.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    $\begingroup$ Use the third argument of Map[]: Map[f, m2, {3}]. $\endgroup$ – J. M. is away May 23 '16 at 16:49
  • $\begingroup$ @J.M. I got confused about this level thing in Map , Total ... . Is there any source about that. $\endgroup$ – MOON May 23 '16 at 18:09
  • $\begingroup$ Apart from the docs, how about this question? $\endgroup$ – J. M. is away May 23 '16 at 18:13

Browse other questions tagged or ask your own question.