【发布时间】:2016-04-21 20:49:51
【问题描述】:
sympy.combinatorics.permutations 中的什么函数可以返回给定排列的逆排列?在 Google 中搜索不会给出结果。这个函数我可以写,但是如果sympy已经实现了,那就没必要了。
感谢您的帮助!
【问题讨论】:
标签: python python-2.7 permutation sympy inverse
sympy.combinatorics.permutations 中的什么函数可以返回给定排列的逆排列?在 Google 中搜索不会给出结果。这个函数我可以写,但是如果sympy已经实现了,那就没必要了。
感谢您的帮助!
【问题讨论】:
标签: python python-2.7 permutation sympy inverse
你正在寻找~:
In [5]: print Permutation.__invert__.__doc__
Return the inverse of the permutation.
A permutation multiplied by its inverse is the identity permutation.
Examples
========
>>> from sympy.combinatorics.permutations import Permutation
>>> p = Permutation([[2,0], [3,1]])
>>> ~p
Permutation([2, 3, 0, 1])
>>> _ == p**-1
True
>>> p*~p == ~p*p == Permutation([0, 1, 2, 3])
True
In [6]: ~Permutation(1, 2, 0)
Out[6]: Permutation(0, 2, 1)
** -1 也可以。在线文档从字面上从未解释过这一点,所以我可以看到您是如何找不到它的。 ~ 仅在commutator 和mul_inv 方法的解释中提及。
【讨论】: