2016-09-14 28 views
1

如果我从scikit libary运行dendrogramScikit树状图:如何禁用输出?

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) 

我得到一吨print输出在我的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]} 

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

+0

从来没有使用过它,但文档:http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.cluster.hierarchy .dendrogram.html状态您可以传递'p'和'truncate'参数,这可能有助于您控制输出的详细程度 – EdChum

回答

1

打印重定向到什么:

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!