gpt4 book ai didi

python - Scikit 树状图 : How to disable ouput?

转载 作者:太空宇宙 更新时间:2023-11-03 16:08:43 25 4
gpt4 key购买 nike

如果我从 scikit 库运行 dendrogram:

from scipy.cluster.hierarchy import linkage, dendrogram
# ...
X = np.asarray(X)
Z = linkage(X, 'single', 'correlation')
plt.figure(figsize=(16,8))
dendrogram(Z, color_threshold=0.7)

我在 ipython 笔记本中得到了大量print输出:

{'color_list': ['g',
'r',
'c',
'm',
'y',
...
0.70780175324891315,
0.70172263980890581],
[0.0, 0.54342622932769225, 0.54342622932769225, 0.0],
[0.0, 0.46484932243120658, 0.46484932243120658, 0.0],
...
177,
196,
82,
19,
108]}

如何禁用此功能?我只对实际的树状图感兴趣。

最佳答案

将打印重定向为空:

import os
import sys
f = open(os.devnull, 'w')
temp = sys.stdout
sys.stdout = f

# print is disabled here

sys.stdout = temp

# print works again!

关于python - Scikit 树状图 : How to disable ouput?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39492171/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com