当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python SymPy Permutation.cycle_structure()用法及代码示例


Permutation.cycle_structure():cycle_structure()是一个sympy Python库函数,它以字典形式返回置换的循环结构,这将指示每个循环长度的多样性。

用法:
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()示例– 2D排列

# 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}



相关用法


注:本文由纯净天空筛选整理自noobestars101大神的英文原创作品 Python | SymPy Permutation.cycle_structure() method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。