Python中的SymPy Permutation.parity()
Permutation.parity() : parity()是一个Sympy Python库函数,用于返回 permutation 的奇偶性。它指的是排列组合中的反转数的奇偶性。
语法 : sympy.combinatorics.permutations.Permutation.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()示例–二维互换
# 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