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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:30:33+00:00 2026-05-28T03:30:33+00:00

I’m learning about graphs(they seem super useful) and was wondering if I could get

  • 0

I’m learning about graphs(they seem super useful) and was wondering if I could get some advice on a possible way to structure my graphs.

Simply, Lets say I get purchase order data everyday and some days its the same as the day before and on others its different. For example, yesterday I had an order of pencils and erasers, I create the two nodes to represent them and then today I get an order for an eraser and a marker, and so on. After each day, my program also looks to see who ordered what, and if Bob ordered a pencil yesterday and then an eraser today, it creates a directed edge. My logic for this is I can see who bought what on each day and I can track the purchase behaviour of Bob(and maybe use it to infer patterns with himself or other users).

My problem is, I’m using networkx(python) and creating a node ‘pencil’ for yesterday and then another node ‘pencil’ for day2 and I can’t differentiate them.

I thought(and have been) naming it day2-pencil and then scanning the entire graph and stripping out the ‘day2-‘ to track pencil orders. This seems wrong to me(not to mention expensive on the processor). I think the key would be if I can somehow mark each day as its own subgraph so when I want to study a specific day or a few days, I don’t have to scan the entire graph.

As my test data gets larger, its getting more and more confusing so I am wondering what the best practice is? Any generate suggestions would be great(as networkx seems pretty full featured so they probably have a way of doing it).

Thanks in advance!

Update: Still no luck, but this maybe helpful:

import networkx as nx
G=nx.Graph()
G.add_node('pencil', day='1/1/12', colour='blue')
G.add_node('eraser', day='1/1/12', colour='rubberish colour. I know thats not a real colour')
G.add_node('pencil', day='1/2/12', colour='blue')

The result I get typing the following command G.node is:

{'pencil': {'colour': 'blue', 'day': '1/2/12'}, 'eraser': {'colour': 'rubberish colour. I know thats not a real colour', 'day': '1/1/12'}}

Its obviously overwriting the pencil from 1/1/12 with 1/2/12 one, not sure if I can make a distint one.

  • 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-05-28T03:30:33+00:00Added an answer on May 28, 2026 at 3:30 am

    This is mostly depending on your goal actually. What you want to analyze is the definitive factor in your graph design. But, looking at your structure, a general structure would be nodes for Customers and Products, that are connected by Days (I don’t know if this would help you any better but this is in fact a bipartite graph).

    So your structure would be something like this:

    node(Person) --- edge(Day) ---> node(Product)
    

    Let’s say, Bob buys a pencil on 1/1/12:

    node(Bob) --- 1/1/12 ---> node(Pencil)
    

    Ok, now Bob goes and buys another pencil on 1/2/12:

              -- 1/1/12 --
             /            \
    node(Bob)              > node(Pencil)
             \            /
              -- 1/2/12 --
    

    so on…

    This is actually possible with networkx. Since you have multiple edges between nodes, you have to choose between MultiGraphMor MultiDiGraph depending on the directed-ness of your edges.

    In : g = networkx.MultiDiGraph()
    
    In : g.add_node("Bob")
    In : g.add_node("Alice")
    
    In : g.add_node("Pencil")
    
    In : g.add_edge("Bob","Pencil",key="1/1/12")
    In : g.add_edge("Bob","Pencil",key="1/2/12")
    
    In : g.add_edge("Alice","Pencil",key="1/3/12")
    In : g.add_edge("Alice","Pencil",key="1/2/12")
    
    In : g.edges(keys=True)
    Out:
    [('Bob', 'Pencil', '1/2/12'),
     ('Bob', 'Pencil', '1/1/12'),
     ('Alice', 'Pencil', '1/3/12'),
     ('Alice', 'Pencil', '1/2/12')]
    

    so far, not bad. You can actually query things like “Did Alice buy a Pencil on 1/1/12?”.

    In : g.has_edge("Alice","Pencil","1/1/12")
    Out: False
    
    In : g.has_edge("Alice","Pencil","1/2/12")
    Out: True
    

    Things might get bad if you want all orders on specific days. By bad, I don’t mean code-wise, but computation-wise. Code-wise it is rather simple:

    In : [(from_node, to_node) for from_node, to_node, key in g.edges(keys=True) if key=="1/2/12"]
    Out: [('Bob', 'Pencil'), ('Alice', 'Pencil')]
    

    But this scans all the edges in the network and filters the ones you want. I don’t think networkx has any better way.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I am using Paperclip to handle profile photo uploads in my app. They upload
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I have some data like this: 1 2 3 4 5 9 2 6

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.