繁体   English   中英

Scikit 树状图:如何禁用输出?

[英]Scikit dendrogram: How to disable ouput?

如果我从 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!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM