📜  SymPy | Python中的 Prufer.to_prufer()

📅  最后修改于: 2022-05-13 01:55:23.219000             🧑  作者: Mango

SymPy | Python中的 Prufer.to_prufer()

Prufer.to_prufer() : to_prufer()是一个 sympy Python库函数,它返回参数树的 Prufer 序列,该参数树以边列表的形式给出, n是树中的节点数。

代码 #1:to_prufer() 示例

# Python code explaining
# SymPy.Prufer.size()
  
# importing SymPy libraries
from sympy.combinatorics import Permutation, Cycle
from sympy.combinatorics.prufer import Prufer
  
# Using from 
# sympy.combinatorics.prufer.Prufer.size()
  
# Creating Prufer
a = Prufer([1, 2, 3], [2, 4, 5])
  
# size value
print ("Prufer a size : ", a.to_prufer([[0, 1], [0, 2], [0, 3]], 4))

输出 :

代码 #2:to_prufer() 示例

# Python code explaining
# SymPy.Prufer.size()
  
# importing SymPy libraries
from sympy.combinatorics import Permutation, Cycle
from sympy.combinatorics.prufer import Prufer
  
# Using from 
# sympy.combinatorics.prufer.Prufer.size()
  
# Creating Prufer
b = Prufer([1, 2, 3, 2, 4, 5], [6, 7], [8])
  
# size value
print ("Prufer b size : ", b.to_prufer([[0, 1], [0, 2], [0, 3]], 4))

输出 :