Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9244877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:08:19+00:00 2026-06-18T09:08:19+00:00

I have a distance matrix presents the distance matrix for pairwise elements such as

  • 0

I have a distance matrix presents the distance matrix for pairwise elements
such as

    A B C D .....
A   n1 n2 n3
B n1    
C n2 n4
D n3 n5 ....... 
E.........

i input the array like for clustering

 arry=  [ 0 n1, n2, n3..
   n1.......
   n2 n4
   n3 n5 ]


Y=sch.linkage(arry,'single')
cutoff=1e-6
T=sch.fcluster(Y, cutoff,'distance')
print T

Z=sch.dendrogram(Y, color_threshold=cutoff)

my fcluster output is like
[ 4 10 12 1 5 13 2 11 1 7 8 3 14 6 10 16 9 15 1 7]
from a previous poster of others
Clustering with scipy – clusters via distance matrix, how to get back the original objects

I understand
the output T[i] only presents the number of element in a cluster ..how I link the original element A, B ,C ,D ,E….. elements with the cluster result and the dendrogram? and lab them properly into my figures.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:08:20+00:00Added an answer on June 18, 2026 at 9:08 am

    “I understand the output T[i] only presents the number of element in a cluster…”

    T[j] is the “cluster number” of the j-th data point. That is, fcluster provides the assignments of data points to clusters. So, for example, if there are five data points, and fcluster puts the first, second and last in cluster 1 and the others in cluster 2, the return value of fcluster will be array([1, 1, 2, 2, 1]).

    Here’s a demo that shows how you can pull that data apart. For convenience, I’ve used fclusterdata instead of the combination of linkage and fcluster. fclusterdata returns the same thing as fcluster.

    import numpy as np
    
    def cluster_indices(cluster_assignments):
        n = cluster_assignments.max()
        indices = []
        for cluster_number in range(1, n + 1):
            indices.append(np.where(cluster_assignments == cluster_number)[0])
        return indices
    
    if __name__ == "__main__":
        from scipy.cluster.hierarchy import fclusterdata
    
        # Make some test data.
        data = np.random.rand(15,2)
    
        # Compute the clusters.
        cutoff = 1.0
        cluster_assignments = fclusterdata(data, cutoff)
    
        # Print the indices of the data points in each cluster.
        num_clusters = cluster_assignments.max()
        print "%d clusters" % num_clusters
        indices = cluster_indices(cluster_assignments)
        for k, ind in enumerate(indices):
            print "cluster", k + 1, "is", ind
    

    Typical output:

    4 clusters
    cluster 1 is [ 0  1  6  8 10 13 14]
    cluster 2 is [ 3  4  5  7 11 12]
    cluster 3 is [9]
    cluster 4 is [2]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a distance matrix composed of pair-wise levenshtein's distance. I was using scikits-learn.
Users I have a distance matrix dMat and want to find the 5 nearest
Can anyone suggest some clustering algorithm which can work with distance matrix as an
I have a 40*4 matrix M and a vector A with 40 elements. I
Suppose I have an n*n matrix of distances between n users. I'd like to
I have the following distance matrix in csv format. http://palaeomath.palass.org/images/mds/T1.jpg Using PHP, how could
I have a (symmetric) matrix M that represents the distance between each pair of
I have a set of points (with unknow coordinates) and the distance matrix. I
I have a distance field in my database that stores the distance traveled on
I have several nodes (undirected graph, bidirecional) ... Each two nodes have a distance...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.