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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:54:44+00:00 2026-06-06T05:54:44+00:00

I am trying to find out which edges from a graph are bidirectional. Each

  • 0

I am trying to find out which edges from a graph are bidirectional. Each row is an edge. For each starting node A, I am searching each corresponding end node B if they have node A as an ending point:

for ending_point_B in nodeA:
    nodeA in ending_points_of_B

Disregard for now repeated entries in df[‘S’]. How can I optimize this search? I suspect something along the lines of groupby. This way takes too much time for my real graph.

Thank you

from pandas import *

def missing_node(node):
    set1 = set(df[df.E == node].S.values)
    set2 = set(df.E[df.S == node].values)
    return list(set1.difference(set2))

x = [1,1,2,2,3]
y = [2,3,1,3,1]

df = DataFrame([x,y]).T
df.columns = ['S','E'] #Start & End

df['Missing'] = df.S.apply(missing_node)

df:

   S  E Missing
0  1  2      []
1  1  3      []
2  2  1      []
3  2  3      []
4  3  1     [2]
  • 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-06T05:54:46+00:00Added an answer on June 6, 2026 at 5:54 am

    Pandas is great, but not sure you need it here. Something like the following should give you the links that aren’t bidirectional:

    x = [1,1,2,2,3]
    y = [2,3,1,3,1]
    
    fwd = set( zip(x,y) )
    rev = set( zip(y,x) )
    print ' not bi: ', fwd.difference(rev)
    

    This returns:

    not bi: set([(2, 3)])

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

Sidebar

Related Questions

I'm trying to figure out a way to find out which files were affected
I am trying to find some code which will help me to find out
I am trying to find out which is the proper way to fetch data
I am trying to find out which event i should put my code that
I'm new to Windows networking, and I am trying to find out which PORT
I am trying to find out which version of OpenMP is installed on my
I am trying to find out which Hypervisor will allow me to grant access
I'm trying to use tasklist to find out which process is consuming more than
What I am trying to do is find out which fields were updated and
I've been trying to find out which version of SOAP 1.1/1.2 being using in

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.