import networkx as nx
import numpy as np
def is_isomorphic(graph1, graph2):
G1 = nx.from_numpy_matrix(graph1)
G2 = nx.from_numpy_matrix(graph2)
isomorphic = nx.is_isomorphic(G1,G2)
print("isomorphic? \t", str(isomorphic))
return isomorphic
graph1 = np.array([[1, 0.5, 1.5],
[0, 1, 0],
[0, 0, 2]])
graph2 = np.array([[1, 0, 1.5],
[0, 1, 1.5],
[0, 0, 2]])
print(is_isomorphic(graph1,graph2))
Suppose I have two graphs: graph1 with node 1 being bonded with a node 1 and 2 and graph2 where node 2 is being bonded with two node 1s. So if we look at these graphs as molecules, these two graphs are not isomorphic. Now when I call is_isomorphic(), this results in a True value, meaning that the two graphs are isomorphic.
How do I make sure that the weights are being taken into account?
Thank you!