SymPy | Python中的 Permutation.parity()
Permutation.parity() : parity()是一个 sympy Python库函数,它返回排列的奇偶性。它意味着排列中反转次数的奇偶性。
Syntax : sympy.combinatorics.permutations.Permutation.parity()
Return : next permutation in lexicographical parity
代码 #1:parity() 示例
# Python code explaining
# SymPy.Permutation.parity()
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
# Using from sympy.combinatorics.permutations.Permutation.parity() method
# creating Permutation
a = Permutation([[2, 0], [3, 1]])
b = Permutation([1, 3, 5, 4, 2, 0])
print ("Permutation a - parity form : ", a.parity())
print ("Permutation b - parity form : ", b.parity())
输出 :
Permutation a – parity form : 0
Permutation b – parity form : 1
代码 #2:parity() 示例– 2D 排列
# Python code explaining
# SymPy.Permutation.parity()
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
# Using from sympy.combinatorics.permutations.Permutation.parity() method
# creating Permutation
a = Permutation([[2, 4, 0],
[3, 1, 2],
[1, 5, 6]])
print ("Permutation a - parity form : ", a.parity())
输出 :
Permutation a – parity form : 0