SymPy | Python中的 Permutation.length()
Permutation.length() :length()是一个 sympy Python库函数,用于查找由排列移动的整数的数量。
Syntax : sympy.combinatorics.permutations.Permutation.length()
Return : number of integers moved by the permutation
代码 #1:length() 示例
# Python code explaining
# SymPy.Permutation.length()
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
# Using from sympy.combinatorics.permutations.Permutation.length() method
# creating Permutation
a = Permutation([[2, 0], [3, 1]])
b = Permutation([1, 3, 5, 4, 2, 0])
print ("Permutation a - length form : ", a.length())
print ("Permutation b - length form : ", b.length())
输出 :
Permutation a – length form : 4
Permutation b – length form : 6
代码 #2:length() 示例——二维排列
# Python code explaining
# SymPy.Permutation.length()
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
# Using from sympy.combinatorics.permutations.Permutation.length() method
# creating Permutation
a = Permutation([[2, 4, 0],
[3, 1, 2],
[1, 5, 6]])
print ("Permutation a - length form : ", a.length())
输出 :
Permutation a – length form : 7