Python| SymPy Permutation.index() 方法
Permutation.index() : index()是一个 sympy Python库函数,它返回参数中排列的索引值。
排列的索引 =所有下标 j 的总和,使得 permutation[j] 大于 permutation[j+1]。
Syntax :
sympy.combinatorics.permutations.Permutation.index()
Return :
index value of the permutation
代码 #1:index() 示例
# Python code explaining
# SymPy.Permutation.index()
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
# Using from sympy.combinatorics.permutations.Permutation.index() method
# creating Permutation
a = Permutation([[2, 0], [3, 1]])
b = Permutation([1, 3, 5, 4, 2, 0])
print ("Permutation a - index form : ", a.index())
print ("Permutation b - index form : ", b.index())
输出 :
Permutation a – index form : 1
Permutation b – index form : 9
代码 #2 : index() 示例– 2D 排列
# Python code explaining
# SymPy.Permutation.index()
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
# Using from sympy.combinatorics.permutations.Permutation.index() method
# creating Permutation
a = Permutation([[2, 4, 0],
[3, 1, 2],
[1, 5, 6]])
print ("Permutation a - index form : ", a.index())
输出 :
Permutation a – index form : 8