Python| SymPy Permutation.atoms() 方法
Permutation.atoms() :atoms()是一个 sympy Python库函数,它返回排列中存在的所有元素。
Syntax : sympy.combinatorics.permutations.Permutation.atoms()
Return : elements of the argumented permutation.
代码 #1:atoms() 示例
# Python code explaining
# SymPy.Permutation.atoms()
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
# Using from sympy.combinatorics.permutations.Permutation.atoms() method
# creating Permutation
a = Permutation([[2, 0], [3, 1]])
b = Permutation([1, 3, 5, 4, 2, 0])
print ("Permutation a - atoms form : ", a.atoms())
print ("Permutation b - atoms form : ", b.atoms())
输出 :
Permutation a – atoms form : {0, 1, 2, 3}
Permutation b – atoms form : {0, 1, 2, 3, 4, 5}
代码 #2:atoms() 示例– 2D 排列
# Python code explaining
# SymPy.Permutation.atoms()
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
# Using from sympy.combinatorics.permutations.Permutation.atoms() method
# creating Permutation
a = Permutation([[2, 4, 0],
[3, 1, 2],
[1, 5, 6]])
print ("Permutation a - atoms form : ", a.atoms())
输出 :
Permutation a – ascents form : [1, 2, 4]