SymPy | Python中的 Prufer.edges()
Prufer.edges() :edges()是一个 sympy Python库函数,它返回节点数和给定运行的边列表,这些运行连接整数标记树中的节点。
Syntax :
sympy.combinatorics.Prufer.prufer.edges()
Return :
number of nodes and a list of edges
代码 #1:edges() 示例
# Python code explaining
# SymPy.Prufer.edges()
# importing SymPy libraries
from sympy.combinatorics import Permutation, Cycle
from sympy.combinatorics.prufer import Prufer
# Using from
# sympy.combinatorics.prufer.Prufer.edges()
# Creating Prufer
a = Prufer.edges([1, 2, 3], [2, 4, 5])
# edge value
print ("Prufer a edges : ", a)
输出 :
Prufer a edges : ([[0, 1], [1, 2], [1, 3], [3, 4]], 5)
代码 #2:edges() 示例
# Python code explaining
# SymPy.Prufer.edges()
# importing SymPy libraries
from sympy.combinatorics import Permutation, Cycle
from sympy.combinatorics.prufer import Prufer
# Using from
# sympy.combinatorics.prufer.Prufer.edges()
# Creating Prufer
b = Prufer.edges([1, 2, 3, 2, 4, 5], [6, 7], [8])
# edge value
print ("Prufer b edges : ", b)
输出 :
Prufer b edges : ([[0, 1], [1, 2], [1, 3], [3, 4], [5, 6]], 7)