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 7765799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:15:13+00:00 2026-06-01T15:15:13+00:00

I am 2 days old with python and coding in general, I have been

  • 0

I am 2 days old with python and coding in general, I have been working on making a random geometric graph that is 2mode. To do this I have been looking at the code in networkx here

I started using the following logic

import networkx as nx
def my_bipartite_geom_graph(a, b, radius, dim):

G=nx.Graph()
A=nx.Graph()
A.name="a node set"
A.add_nodes_from(range(a)) 
for n in A:
    A.node[n]['pos']=[random.random() for i in range(0,dim)]

B=nx.Graph()
B.name="b node set"
B.add_nodes_from(range(b)) 
for n in B:
    B.node[n]['pos']=[random.random() for i in range(0,dim)]

G=nx.disjoint_union(A,B)

nodesa = A.nodes(data=True)
nodesb = B.nodes(data=True)
while nodesa:
    u,du = nodesa.pop()
    pu = du['pos']
    for v,dv in nodesb:
        pv = dv['pos']
        d = sum(((a-b)**2 for a,b in zip(pu,pv)))
        if d <= radius**2:
            G.add_edge(u,v)
return G

This returns a graph but clearly not what i was hoping for. Any pointers on how better to approach this problem would be greatly appreciated.

Best Wishes

  • 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-01T15:15:15+00:00Added an answer on June 1, 2026 at 3:15 pm

    The problem is nx.disjoint_union renumbers your nodes so that they are distinct. That means B[n] != G[n]. So the node labels in B contains nodes from A in the G graph.

    Here is one way to solve it:

    import networkx as nx
    def my_bipartite_geom_graph(a, b, radius, dim):
    
        G=nx.Graph()
        G.add_nodes_from(range(a+b))
        for n in range(a):
            G.node[n]['pos']=[random.random() for i in range(0,dim)]
            G.node[n]['type'] = 'A'
    
        for n in range(a, a+b):
            G.node[n]['pos']=[random.random() for i in range(0,dim)]
            G.node[n]['type'] = 'B'
    
        nodesa = [(node, data) for node, data in G.nodes(data=True) if data['type'] == 'A']
        nodesb = [(node, data) for node, data in G.nodes(data=True) if data['type'] == 'B']
    
        while nodesa:
            u,du = nodesa.pop()
            pu = du['pos']
            for v,dv in nodesb:
                pv = dv['pos']
                d = sum(((a-b)**2 for a,b in zip(pu,pv)))
                if d <= radius**2:
                    G.add_edge(u,v)
        return G
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am just two days old in using JMeter . I have been asked
I have a clone of my repo that is a few days old. I
Weird question, but one that puzzles me a bit. In the old days when
From my old Access days, there was a First() function that allowed you to
I have a device that supports 4-color graphics (much like CGA in the old
I have this line in a useful Bash script that I haven't managed to
I have this command that I run everyday via cron: find /home/get/public_html/videos -daystart -maxdepth
I am trying to find a file that are 0 days old. Below are
I have this php code that should take all the php files in a
I have several directories and I want directories over 7 days old to be

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.