How to use user-defined class object as a networkx node?

前端 未结 2 1428
执念已碎
执念已碎 2021-01-05 08:07

Class point is defined as (there are also some methods, atributes, and stuff in it, but this is minimal part):

class point():
    def ___init___(self, x, y):         


        
2条回答
  •  温柔的废话
    2021-01-05 09:12

    You have added a node and as such, you can examine the nodes which is a set-like view. Quoting from the docs:

    These are set-like views of the nodes, edges, neighbors (adjacencies), and degrees of nodes in a graph. They offer a continually updated read-only view into the graph structure.

    Do for example:

    mynodes = list(G.nodes())
    print(mynodes)
    

    You should be now able to also do:

    mynode = mynodes[0]  # because we have converted the set-like view to a list
    

    See the tutorial: https://networkx.github.io/documentation/stable/tutorial.html

提交回复
热议问题