What's the inverse of f[x_]:=Flatten[x] where x is Array with dimensions dims?
+11
A:
There is no built-in function, but it's pretty easy with a combination of Fold
and Partition
:
In[47]:= x1 = RandomReal[{0, 1}, {3, 4, 5}];
In[48]:= dims = Dimensions[x1]
Out[48]= {3, 4, 5}
In[49]:= x2 = Fold[Partition[#, #2] &, Flatten[x1], Most[Reverse[dims]]];
In[50]:= x1 == x2
Out[50]= True
Michael Pilat
2010-09-27 22:07:34
Wow, nice, a lot cleaner than my version
Yaroslav Bulatov
2010-09-28 04:01:28