用sympy反转排列

用户9123

哪个函数sympy.combinatorics.permutations可以返回给定排列的逆排列?Google中的搜索没有结果。我可以编写此功能,但是如果已经在中实现了该功能,sympy则将没有必要。

谢谢你的帮助!

user2357112支持Monica

您正在寻找~

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也可以。在线文档从字面上从未解释过这一点,因此我可以看看您是怎么找到它的。~仅在commutatormul_inv方法的说明中提及

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章