2016-09-14 31 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!