Open In App

SymPy | Permutation.inversions() in Python

Last Updated : 26 Aug, 2019
Improve
Improve
Like Article
Like
Save
Share
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




# 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




# 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



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads