SymPy | Python中的 Prufer.to_tree()
Prufer.to_tree() : to_tree()是一个 sympy Python库函数,它返回 Prufer 序列的树表示。
Syntax :
sympy.combinatorics.Prufer.prufer.to_tree()
Return :
representation of the Prufer sequence
代码 #1:to_tree() 示例
# Python code explaining
# SymPy.Prufer.to_tree()
# importing SymPy libraries
from sympy.combinatorics import Permutation, Cycle
from sympy.combinatorics.prufer import Prufer
# Using from
# sympy.combinatorics.prufer.Prufer.to_tree()
# Creating Prufer
a = Prufer([1, 2, 3], [2, 4, 5], 4)
# to_tree value
print ("Prufer a to_tree : ", Prufer.to_tree([0, 2]))
输出 :
Prufer a to_tree : [[0, 1], [0, 2], [2, 3]]
代码 #2:to_tree() 示例
# Python code explaining
# SymPy.Prufer.to_tree()
# importing SymPy libraries
from sympy.combinatorics import Permutation, Cycle
from sympy.combinatorics.prufer import Prufer
# Using from
# sympy.combinatorics.prufer.Prufer.to_tree()
# Creating Prufer
b = Prufer([1, 2, 3, 2, 4, 5], [6, 7], [8], 4)
# to_tree value
print ("Prufer b to_tree : ", Prufer.to_tree([0, 2]))
输出 :
Prufer b to_tree : [[0, 1], [0, 2], [2, 3]]