I create a graph with some edges:
import networkx as nx
g = nx.Graph()
g.add_edge(1, 2)
g.add_edge(2, 6)
g.add_edge(3, 4)
g.add_edge(5, 6)
print(g.edges)
output-> (1, 2), (1, 5), (2, 6), (5, 6), (3, 4)
And then getting adjacent A by making use of graph g
nx.convert_matrix.to_numpy_array(g)
The result is :
array([[0., 1., 1., 0., 0., 0.],
[1., 0., 0., 1., 0., 0.],
[1., 0., 0., 1., 0., 0.],
[0., 1., 1., 0., 0., 0.],
[0., 0., 0., 0., 0., 1.],
[0., 0., 0., 0., 1., 0.]])
You can see that adjacent not match g if you regard the indices of elements on adjacent as following:
A : 1 2 3 4 5 6
—————————————
1 | 0 1 1 0 0 0
2 | 1 0 0 1 0 0
3 | 1 0 0 1 0 0
4 | 0 1 1 0 0 0
5 | 0 0 0 0 0 1
6 | 0 0 0 0 1 0
For example:
On A, the value of indices (1, 3) equal 1, as usual, which means edges (1, 3) is exist, but actually not !
If I change the indices of A to this as below:
A : 1 2 5 6 3 4
—————————————
1 | 0 1 1 0 0 0
2 | 1 0 0 1 0 0
5 | 1 0 0 1 0 0
6 | 0 1 1 0 0 0
3 | 0 0 0 0 0 1
4 | 0 0 0 0 1 0
the match will be right between edges and A.
My question
How to make A's indices follow the normal order -> 1,2,3,4...
Thanks in advance ~