SymPy | Permutation.inversions() in Python
Last Updated :
26 Aug, 2019
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
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import 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
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import 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
Share your thoughts in the comments
Please Login to comment...