OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to add a feature to all the nodes in networkx

  • Thread starter Thread starter Formal_that
  • Start date Start date
F

Formal_that

Guest
How to assign a number between 0-1 determining the sate of each of the neighbours. (That is in principle, each node has a number(state) associated to it! So that when I call a node; it has the information of its neighbours and their corresponding states! something like a multi-dimensional array in C!

So that the final information is something like ; node 5 has 4 neighbours which are 1,2,3,4 each with a state 0.1,0.4,0.6,0.8. I will further use these states in my calculations, so preferably an array containing this information will work.

Code:
import networkx as nx
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

G = nx.barabasi_albert_graph(100,2)

for u in G.nodes():
    neighbors = nx.neighbors(G, u)
    print(neighbors)
<p>How to assign a number between 0-1 determining the sate of each of the neighbours. (That is in principle, each node has a number(state) associated to it! So that when I call a node; it has the information of its neighbours and their corresponding states! something like a multi-dimensional array in C!</p>
<p>So that the final information is something like ; node 5 has 4 neighbours which are 1,2,3,4 each with a state 0.1,0.4,0.6,0.8. I will further use these states in my calculations, so preferably an array containing this information will work.</p>
<pre><code>import networkx as nx
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

G = nx.barabasi_albert_graph(100,2)

for u in G.nodes():
neighbors = nx.neighbors(G, u)
print(neighbors)
</code></pre>
 

Latest posts

Top