I have a $N$ dimensional array $M$, and a function $f(\{M_{i}\})$ in terms of the array elements, where each matrix element $M_{i}$ can be 0 or 1. I'd like to construct a table
Table[f(\{M_{ij}\}), {M_{1},0,1},{M_{2},0,1},...,{M_{N},0,1}]
For a given N, I can write down the code to construct the table, but for general N, it there a convenient way to write the above code? Namely, I'd like to keep N as an input variable.
As an example, let us use
n=3;
Mat=Table[M[i],{i,1,n}];
and define f as the sum of all the elements in Mat. so the table I want to construct is
Table[Sum[M[i],{i,1,n}], {M[1],0,1},{M[2],0,1}, {M[3],0,1}]
The outcome is
{{{0, 1}, {1, 2}}, {{1, 2}, {2, 3}}}
Of course, when I change n to other values, I need to rewrite the code for the table. So there should be a way for us to construct the table without modifying the code.
Map
your function $f$ on each element of the matrix $M$. WouldMap[f, M, {2}]
do what you want? $\endgroup$f[mi_] := <do something with the mi value>
so for each different value in $M$, $f$ will do whatever you want with it. I second @march’s request though. If you show us an example of input and desired output, this will be much easier. $\endgroup$