Inverse of Flatten in Mathematica?

扶醉桌前 提交于 2019-11-29 21:19:06

问题


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


回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/3807976/inverse-of-flatten-in-mathematica

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!