SymPy | Python中的 Permutation.rank_nonlex()
Permutation.rank_nonlex() :rank_nonlex()是一个 sympy Python库函数,它返回非词典排列的等级。
Syntax : sympy.combinatorics.permutations.Permutation.rank_nonlex()
Return : rank of non lexicographical permutation.
代码 #1:rank_nonlex() 示例
# Python code explaining
# SymPy.Permutation.rank_nonlex()
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
# Using from
# sympy.combinatorics.permutations.Permutation.rank_nonlex() method
# creating Permutation
a = Permutation([[2, 0], [3, 1]])
b = Permutation([1, 3, 5, 4, 2, 0])
print ("Permutation a - rank_nonlex form : ", a.rank_nonlex())
print ("Permutation b - rank_nonlex form : ", b.rank_nonlex())
输出 :
Permutation a – rank_nonlex form : 13
Permutation b – rank_nonlex form : 72
代码 #2 : rank_nonlex() 示例– 2D 排列
# Python code explaining
# SymPy.Permutation.rank_nonlex()
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
# Using from sympy.combinatorics.permutations.Permutation.rank_nonlex() method
# creating Permutation
a = Permutation([[2, 4, 0],
[3, 1, 2],
[1, 5, 6]])
print ("Permutation a - rank_nonlex form : ", a.rank_nonlex())
输出 :
Permutation a – rank_nonlex form : 218