Inverse of Flatten in Mathematica?

后端 未结 2 1799
傲寒
傲寒 2021-01-03 03:22

What\'s the inverse of f[x_]:=Flatten[x] where x is Array with dimensions dims?

相关标签:
2条回答
  • 2021-01-03 03:54

    You probably want Partition[] or one of its relatives.

    0 讨论(0)
  • 2021-01-03 03:59

    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, Flatten[x1], Most[Reverse[dims]]];
    
    In[50]:= x1 == x2
    
    Out[50]= True
    
    0 讨论(0)
提交回复
热议问题