SymPy | Python中的 Subset.iterate_graycode()
Subset.iterate_graycode() : iterate_graycode()是一个 sympy Python库函数,它迭代 k 步以获取相应的格雷码。
Syntax :
sympy.combinatorics.subset.Subset.iterate_graycode()
Return :
iterates over the k steps to get the respective Gray codes
代码 #1:iterate_graycode() 示例
# Python code explaining
# SymPy.Subset.iterate_graycode()
# importing SymPy libraries
from sympy.combinatorics import Permutation, Cycle
from sympy.combinatorics.subsets import Subset
# Using from
# sympy.combinatorics.subset.Subsets.iterate_graycode()
# Creating Subset
a = Subset(['c', 'd'], ['geek', 'for', 'c', 'd'])
# iterate_graycode value
print ("Subset a iterate_graycode : ", a.iterate_graycode(1).subset)
输出 :
Subset a iterate_graycode : [‘c’]
代码 #2 : iterate_graycode() 示例
# Python code explaining
# SymPy.Subset.iterate_graycode()
# importing SymPy libraries
from sympy.combinatorics import Permutation, Cycle
from sympy.combinatorics.subsets import Subset
# Using from
# sympy.combinatorics.subset.Subsets.iterate_graycode()
# Creating Subset
a = Subset(['c', 'd'], ['23', 'c', 'd'])
# iterate_graycode value
print ("Subset a iterate_graycode : ", a.iterate_graycode(3).subset)
输出 :
Subset a iterate_graycode : [’23’, ‘c’, ‘d’]