Python SymPy Permutation.inversion_vector()
Permutation.inversion_vector() : inversion_vector() 是一个Sympy Python库函数,返回参数中permutation的inversion_vector值。
反转向量包括这些元素,其值表示排列组合中<它并位于其右侧的元素的数量。
语法 : sympy.combinatorics.permutations.Permutation.inversion_vector()
返回 :
颠倒_向量的互换值
代码 #1 : inversion_vector() 示例
# Python code explaining
# SymPy.Permutation.inversion_vector()
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
# Using from sympy.combinatorics.permutations.Permutation.inversion_vector() method
# creating Permutation
a = Permutation([[2, 0], [3, 1]])
b = Permutation([1, 3, 5, 4, 2, 0])
print ("Permutation a - inversion_vector form : ", a.inversion_vector())
print ("Permutation b - inversion_vector form : ", b.inversion_vector())
输出 :
Permutation a – inversion_vector form : [2, 2, 0]
Permutation b – inversion_vector form : [1, 2, 3, 2, 1]
代码 #2 : inversion_vector() 例子 – 二维互换
# Python code explaining
# SymPy.Permutation.inversion_vector()
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
# Using from sympy.combinatorics.permutations.Permutation.inversion_vector() method
# creating Permutation
a = Permutation([[2, 4, 0],
[3, 1, 2],
[1, 5, 6]])
print ("Permutation a - inversion_vector form : ", a.inversion_vector())
输出 :
Permutation a – inversion_vector form : [3, 2, 2, 2, 0, 1]