data1 = { 'node1': [1,1,1,2],
'node2': [2,3,6,4],
'weight': [1,1,1,1], }
This is the edgelist of a graph.I want to create adjacency matrix from it.The networkx code is showing this output:
output:
[[0 1 1 0 1]
[1 0 0 1 0]
[1 0 0 0 0]
[0 1 0 0 0]
[1 0 0 0 0]]
but the actual output should be:
[[0 1 1 0 0 1]
[1 0 0 1 0 0]
[1 0 0 0 0 0]
[0 1 0 0 0 0]
[0 0 0 0 0 0]
[1 0 0 0 0 0]]
In my opinion the second one should be the output a since in a adjacency matrix the rows and columns represent the nodes of the graph then if the adjacency matrix has only 5 rows and 5 columns then it would be like the graph has 5 nodes only when in fact it has 6 nodes.Its just that the 5 node is not there in the graph.What is the correct output according to mathematical definitions?
This is not really a maths question. You have a correct understanding of what an adjacency matrix should be.
Your problem is a software problem. The networkx code is correct; only 5 vertices were specified in the graph definition: vertices $1,2,3,4,6$. There simply is no vertex called $5$.
To get the behaviour you want, you need to tell networkx that the graph has another vertex, $5$.
Please don't follow up here with questions about how you should get networkx to do this; it's off-topic for a maths forum. Raise a question in stackoverflow or similar.