从Mathematica到Python
就像:
SetPartitions[Table[i, {i, 2, 5}]]
。上面代码的输出是:{{{2,3,4,5}},{{2},{3,4,5}},{2,3},{4,5} },{{2,4,5},{3}},{{2,3,4},{5}},{2,5},{3,4}},{2,3,{2,3, 5},{4}},{{2,4},{3,5}},{{2},{3},{4,5}},{2},{2},{3,4},{ 5}},{{2},{3,5},{4}},{{2,3},{4},{5}},{5}},{2,4},{3},{3},{5},{5} },{{2,5},{3},{4}},{{2},{3},{4},{5}}}}}}
> 。我想在Python中具有这样的输出。我知道这里提出了许多固定的分区问题,但是,没有人能与Mathematica中的订购完全相同。这是类似的概括
SetPartitions[Table[i, {i, a, b}]]
I have an ordered set partitioning function in Mathematica, just like:
SetPartitions[Table[i, {i, 2, 5}]]
. The output of the above code is:{{{2, 3, 4, 5}}, {{2}, {3, 4, 5}}, {{2, 3}, {4, 5}}, {{2, 4, 5}, {3}}, {{2, 3, 4}, {5}}, {{2, 5}, {3, 4}}, {{2, 3, 5}, {4}}, {{2, 4}, {3, 5}}, {{2}, {3}, {4, 5}}, {{2}, {3, 4}, {5}}, {{2}, {3, 5}, {4}}, {{2, 3}, {4}, {5}}, {{2, 4}, {3}, {5}}, {{2, 5}, {3}, {4}}, {{2}, {3}, {4}, {5}}}
. And I want to have exactly the same output like this in Python. I know there are many set partition questions asked here, but, none could give the exact same ordering as in Mathematica. The generalization of this is something like
SetPartitions[Table[i, {i, a, b}]]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论