给定 2 个包含数字 0 到 (n-1) 的列表 (list_1, list_2),如何获得排列 p(S(n) 的元素)使得 p(list_1) = list_2?
我一直在使用 sympy 排列包。到目前为止,我已声明排列如下
from sympy.combinatorics.generators import symmetric, Permutation
p = Permutation([[2, 3], [5]])
print(p(([0, 1, 2, 3, 4, 5]))
:[0, 1, 3, 2, 4, 5]
我想声明给定 2 个列表的排列。例如,我希望元素
排列作用于整数而不是列表中的位置(这样 (01) * [1, 2, 3, 0] = [0, 2, 3, 1],而不是 (01) * [1, 2, 3, 0] = [2, 1, 3, 0])
我该怎么做?
I have been using the sympy permutations package. So far I have declared permutations as follows
from sympy.combinatorics.generators import symmetric, Permutation
p = Permutation([[2, 3], [5]])
print(p(([0, 1, 2, 3, 4, 5]))
out:[0, 1, 3, 2, 4, 5]
I would like to declare a permutation given 2 lists. For example, I would like the element
I would like the permutation to act on integers rather than positions in the list (so that (01) * [1, 2, 3, 0] = [0, 2, 3, 1], instead of (01) * [1, 2, 3, 0] = [2, 1, 3, 0])
How can I do this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅 permutations.py 中有关组合的讨论:
也许是更好的方法,但如果您想按名称而不是位置访问,这似乎可行:
See the discussion about composition in permutations.py:
Maybe a better way to do this, but this seems to work if you want to access by name instead of position: