79448477

Date: 2025-02-18 13:52:28
Score: 0.5
Natty:
Report link

I think the sort of thing done below should work.

import networkx as nx

g = nx.complete_graph(4)

nx.set_node_attributes(g, {1: {"hello": "world"}})
nx.set_edge_attributes(g, {(2, 3): {"foo": "bar"}})

print(str(g.nodes.data()), str(g.edges.data()))

This produces output which shows node and edge attribute data:

[(0, {}), (1, {'hello': 'world'}), (2, {}), (3, {})] [(0, 1, {}), (0, 2, {}), (0, 3, {}), (1, 2, {}), (1, 3, {}), (2, 3, {'foo': 'bar'})]

There may also be some other way explained in this documentation on reading/writing Networkx graphs.

Reasons:
  • Blacklisted phrase (1): this document
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Alex Duchnowski