Skip to content
Related Articles
Python | SymPy Permutation.inversion_vector()
• Last Updated : 27 Aug, 2019

Permutation.inversion_vector() : inversion_vector()
is a sympy Python library function that returns the inversion_vector value of the permutation in 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 :
sympy.combinatorics.permutations.Permutation.inversion_vector()

Return :
inversion_vector value of the permutation

Code #1 : inversion_vector() Example

 `# 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())`

Output :

Permutation a – inversion_vector form : [2, 2, 0]
Permutation b – inversion_vector form : [1, 2, 3, 2, 1]

Code #2 : inversion_vector() Example – 2D Permutation

 `# 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())`

Output :

Permutation a – inversion_vector form : [3, 2, 2, 2, 0, 1]

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up