1

I am creating a graph from a numpy array where the values of the array elements represent weights. See code below. This graph clearly has one isolate. But why is the code for getting isolates not giving me an empty list.

import numpy

A=numpy.matrix([[3,0,1],[0,2,0], [0,0,5]])

G=nx.from_numpy_matrix(A, parallel_edges=False)


matrix([[3, 0, 1],
    [0, 2, 0],
    [0, 0, 5]])



nx.draw(G, node_color = 'green', node_size = 50, with_labels=False)

plt.show()

Graph with one of the 3 nodes is an isolate

nx.degree(G)

4

nx.degree(G)

DegreeView({0: 3, 1: 2, 2: 3})

list(nx.isolates(G))

[]
Kay
  • 567
  • 3
  • 6
  • 15

1 Answers1

0

According to the networkx documentation an 'isolate' is a degree 0 node.

In your case the node has an edge to itself. So it does not have degree 0.

One option to fix this would be to remove self-edges from the graph:

https://stackoverflow.com/a/49428652/2966723

But only do this if they aren't needed for whatever your application is.

Joel
  • 22,598
  • 6
  • 69
  • 93