📜  SymPy | Python中的 Permutation.inversions()

📅  最后修改于: 2022-05-13 01:55:02.683000             🧑  作者: Mango

SymPy | Python中的 Permutation.inversions()

Permutation.inversions() : inversions()是一个 sympy Python库函数,它返回参数中排列的反转次数值。
反演向量包括其值指示编号的那些元素。排列中的元素 < it 并且位于其右侧。

代码 #1:inversions() 示例

# Python code explaining
# SymPy.Permutation.inversions()
  
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
  
# Using from 
# sympy.combinatorics.permutations.Permutation.inversions() method 
  
# creating Permutation
a = Permutation([[2, 0], [3, 1]])
  
b = Permutation([1, 3, 5, 4, 2, 0])
  
  
print ("Permutation a - inversions form : ", a.inversions())
print ("Permutation b - inversions form : ", b.inversions())

输出 :

代码 #2:inversions() 示例– 2D 排列

# Python code explaining
# SymPy.Permutation.inversions()
  
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
  
# Using from sympy.combinatorics.permutations.Permutation.inversions() method 
  
# creating Permutation
a = Permutation([[2, 4, 0], 
                 [3, 1, 2],
                 [1, 5, 6]])
  
  
print ("Permutation a - inversions form : ", a.inversions())

输出 :