Permutation.cycles() : cycles() is a sympy Python library function that returns the number of cycles present in the permutation. This also includes the singleton.
Syntax :
sympy.combinatorics.permutations.Permutation.cycles()Return :
number of cycles present in the permutation
Code #1 : cycles() Example
# Python code explaining # SymPy.Permutation.cycles() # importing SymPy libraries from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
# Using from sympy.combinatorics.permutations.Permutation.cycles() method # creating Permutation a = Permutation([ 2 , 0 , 3 , 1 , 5 , 4 ])
b = Permutation([ 3 , 1 , 2 , 5 , 4 , 0 ])
print ( "Permutation a - cycles form : " , a.cycles)
print ( "Permutation b - cycles form : " , b.cycles)
|
Output :
Permutation a – cycles form : 2
Permutation b – cycles form : 4
Code #2 : cycles() Example – 2D Permutation
# Python code explaining # SymPy.Permutation.cycles() # importing SymPy libraries from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
# Using from # sympy.combinatorics.permutations.Permutation.cycles() method # creating Permutation a = Permutation([[ 2 , 4 , 0 ],
[ 3 , 1 , 2 ],
[ 1 , 5 , 6 ]])
# SELF COMMUTATING print ( "Permutation a - cycles form : " , a.cycles)
|
Output :
Permutation a – cycles form : 1