Open In App

SymPy | Permutation.inversions() in Python

Last Updated : 26 Aug, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
Permutation.inversions() : inversions() is a sympy Python library function that returns the number of inversions value of the permutation in the argument. The inversion vector includes those elements whose value indicates the no. of elements in the permutation that are < it and lie on its right-hand side.
Syntax : Return : number of inversions value of the permutation in argument
Code #1 : inversions() Example Python3 1=1
# 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())
Output :
Permutation a - inversions form : 4 Permutation b - inversions form : 9
Code #2 : inversions() Example - 2D Permutation Python3 1=1
# 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())
Output :
Permutation a - inversions form : 10

Next Article
Article Tags :
Practice Tags :

Similar Reads