Python Scikit树状图:如何禁用输出?
如果我从scikit库运行树状图:Python Scikit树状图:如何禁用输出?,python,scikit-learn,Python,Scikit Learn,如果我从scikit库运行树状图: 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笔记本中获得了大量的打印输出: {'color_list': ['g', '
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笔记本中获得了大量的打印输出:
{'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!
从未使用过它,但是docs:state可以传递p
和truncate
参数,这可能有助于控制输出的详细程度