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

  • Home
  • SEARCH
  • 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 161153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:09:45+00:00 2026-05-11T11:09:45+00:00

Let G be a graph. So G is a set of nodes and set

  • 0

Let G be a graph. So G is a set of nodes and set of links. I need to find a fast way to partition the graph. The graph I am now working has only 120*160 nodes, but I might soon be working on an equivalent problem, in another context (not medicine, but website development), with millions of nodes.

So, what I did was to store all the links into a graph matrix:

M=numpy.mat(numpy.zeros((len(data.keys()),len(data.keys())))) 

Now M holds a 1 in position s,t, if node s is connected to node t. I make sure M is symmetrical M[s,t]=M[t,s] and each node links to itself M[s,s]=1.

If I remember well if I multiply M with M, the results is a matrix that represents the graph that connects vertexes that are reached on through two steps.

So I keep on multplying M with itself, until the number of zeros in the matrix do not decrease any longer. Now I have the list of the connected components. And now I need to cluster this matrix.

Up to now I am pretty satisfied with the algorithm. I think it is easy, elegant, and reasonably fast. I am having trouble with this part.

Essentially I need to split this graph into its connected components.

I can go through all the nodes, and see what are they connected to.

But what about sorting the matrix reordering the lines. But I don’t know if it is possible to do it.

What follows is the code so far:

def findzeros(M):     nZeros=0     for t in M.flat:         if not t:             nZeros+=1     return nZeros  M=numpy.mat(numpy.zeros((len(data.keys()),len(data.keys()))))     for s in data.keys():     MatrixCells[s,s]=1     for t in data.keys():         if t<s:             if (scipy.corrcoef(data[t],data[s])[0,1])>threashold:                 M[s,t]=1                 M[t,s]=1  nZeros=findzeros(M) M2=M*M nZeros2=findzeros(M2)  while (nZeros-nZeros2):     nZeros=nZeros2     M=M2     M2=M*M     nZeros2=findzeros(M2) 

Edit:

It has been suggested that I use SVD decomposition. Here is a simple example of the problem on a 5×5 graph. We shall use this since with the 19200×19200 square matrix is not that easy to see the clusters.

import numpy import scipy  M=numpy.mat(numpy.zeros((5,5)))  M[1,3]=1 M[3,1]=1 M[1,1]=1 M[2,2]=1 M[3,3]=1 M[4,4]=1 M[0,0]=1  print M  u,s,vh = numpy.linalg.linalg.svd(M) print u print s print vh 

Essentially there are 4 clusters here: (0),(1,3),(2),(4) But I still don’t see how the svn can help in this context.

  • 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. 2026-05-11T11:09:46+00:00Added an answer on May 11, 2026 at 11:09 am

    Why not use a real graph library, like Python-Graph? It has a function to determine connected components (though no example is provided). I’d imagine a dedicated library is going to be faster than whatever ad-hoc graph code you’ve cooked up.

    EDIT: NetworkX seems like it might be a better choice than python-graph; its documentation (here for the connected components function) certainly is.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say there is a graph and some set of functions like: create-node ::
Is there an algorithm or set of algorithms that would let you find the
I need to plot a line graph of a set of data. I know
Let's say I have an object graph of Countries / States / Cities, like
I want to draw graph in java script. Let me share my problem with
This is a question about an algorithm to solve a graph theory problem. Let
Dijkstra(G,w,s) { ISS(G,s); let S be an empty set let Q be a priority
Suppose we're given a colored graph. Let G be its automorphism group. How do
I have this simple graph: name -> string ^ | v label let matrix
I looked at different flash chart software (free and commercial) and could find only

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.