Python SymPy Permutation.cycle_structure()方法

Python SymPy Permutation.cycle_structure()方法

Permutation.cycle_structure() : cycle_structure()是一个sympy Python库函数,它以字典形式返回permutation的循环结构,这将表明每个循环长度的倍数。

语法 : sympy.combinatorics.permutations.Permutation.cycle_structure()

返回 :
作为字典的排列组合的循环结构

代码 #1 : cycle_structure() 示例

# Python code explaining
# SymPy.Permutation.cycle_structure()
  
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
  
# Using from 
# sympy.combinatorics.permutations.Permutation.cycle_structure() method 
  
# creating Permutation
a = Permutation([2, 0, 3, 1, 5, 4])
  
b = Permutation([3, 1, 2, 5, 4, 0])
  
  
print ("Permutation a - cycle_structure form : ", a.cycle_structure)
print ("Permutation b - cycle_structure form : ", b.cycle_structure)

输出 :

Permutation a – cycle_structure form : {2: 1, 4: 1}
Permutation b – cycle_structure form : {1: 3, 3: 1}

代码 #2 : cycle_structure() 例子 – 二维排布

# Python code explaining
# SymPy.Permutation.cycle_structure()
  
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
  
# Using from 
# sympy.combinatorics.permutations.Permutation.cycle_structure() method 
  
# creating Permutation
a = Permutation([[2, 4, 0], 
                 [3, 1, 2],
                 [1, 5, 6]])
  
# SELF COMMUTATING    
print ("Permutation a - cycle_structure form : ", a.cycle_structure)

输出 :

Permutation a – cycle_structure form : {7: 1}

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程