简体   繁体   English

在Mathematica中反转Flatten?

[英]Inverse of Flatten in Mathematica?

什么是f [x _]的倒数:= Flatten [x]其中x是具有维度变暗的数组?

There is no built-in function, but it's pretty easy with a combination of Fold and Partition : 没有内置函数,但结合FoldPartition非常简单:

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

你可能想要Partition[]或其中一个亲戚。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM