[SciPy-Dev] adding cut tree function to scipy.cluster

Skipper Seabold jsseabold at gmail.com
Tue May 12 09:10:04 EDT 2015


Hi,

I wanted to solicit feedback on adding a function similar to R's cutree [1]
to scipy.cluster. PR here [2]

It takes a linkage matrix and returns an array where each step is the group
to which each observation was merged at any given agglomeration step.

Example from the docstring:



>>> from scipy import cluster >>> np.random.seed(23) >>> X =
np.random.randn(50, 4) >>> Z = cluster.hierarchy.ward(X) >>> cutree =
cluster.hierarchy.cut_tree(Z, n_clusters=[5, 10]) >>> cutree[:10]
array([[0, 0], [1, 1], [2, 2], [3, 3], [3, 4], [2, 2], [0, 0], [1, 5], [3,
6], [4, 7]])


[1] https://stat.ethz.ch/R-manual/R-patched/library/stats/html/cutree.html
[2] https://github.com/scipy/scipy/pull/4796
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20150512/ebc93d30/attachment.html>


More information about the SciPy-Dev mailing list