相关疑难解决方法(0)

将`GatherBy`转换为不同的列表

我有listAlistB相同的大小.我做GatherBylistA,这是重排列表.应用相同重排的优雅方法是什么listB

例如

listA = {1, 2, 3};
listB = {a, b, c};
listA1 = GatherBy[{1, 2, 3}, OddQ];
Run Code Online (Sandbox Code Playgroud)

listB1 应该成为 {{a, c}, {b}}

更新 感谢有趣的想法,我最终做了类似于belisarius的事情.这让我想起了Python的"decorate-sort-undecorate"模式

decorated = Thread[{listA, listB}];
grouped = GatherBy[decorated, OddQ[First[#]] &];
listB1 = Map[Last, grouped, {2}]
Run Code Online (Sandbox Code Playgroud)

wolfram-mathematica

7
推荐指数
1
解决办法
316
查看次数

在Mathematica中反转Flatten?

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

wolfram-mathematica

5
推荐指数
1
解决办法
1907
查看次数

标签 统计

wolfram-mathematica ×2