Python | SymPy Permutation.cycles() method
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
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import 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
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 - cycles form : " , a.cycles)
|
Output :
Permutation a – cycles form : 1
Last Updated :
26 Aug, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...