title: Connected components from an adjacency matrix using Numpy or Scipy
body: <p>I've the following adjacency matrix: </p>
  
  <pre><code>array([[0, 1, 1, 0, 0, 0, 0],
         [1, 0, 1, 0, 0, 0, 0],
         [1, 1, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 1, 0, 1],
         [0, 0, 0, 1, 0, 1, 0],
         [0, 0, 0, 0, 1, 0, 1],
         [0, 0, 0, 1, 0, 1, 0]])
  </code></pre>
  
  <p>Which can be drawn like that:</p>
  
  <p><a href="https://i.stack.imgur.com/J6zXU.png" rel="noreferrer"><img src="https://i.stack.imgur.com/J6zXU.png" alt="enter image description here"></a></p>
  
  <p>My goal is to identify the connected graph ABC and DEFG. It's seems that <strong>Depth-First Search</strong> algorithm is what I need and that Scipy <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csgraph.depth_first_order.html" rel="noreferrer">implemented it</a>. So here is my code:</p>
  
  <pre><code>from scipy.sparse import csr_matrix
  from scipy.sparse.csgraph import depth_first_order
  import numpy as np
  
  test = np.asarray([
      [0, 1, 1, 0, 0, 0, 0],
      [1, 0, 1, 0, 0, 0, 0],
      [1, 1, 0, 0, 0, 0, 0],
      [0, 0, 0, 0, 1, 0, 1],
      [0, 0, 0, 1, 0, 1, 0],
      [0, 0, 0, 0, 1, 0, 1],
      [0, 0, 0, 1, 0, 1, 0]
  ])
  
  graph = csr_matrix(test)
  result = depth_first_order(graph, 0)
  </code></pre>
  
  <p>But I don't get the result: </p>
  
  <pre><code>&gt;&gt;&gt; result
  (array([0, 1, 2]), array([-9999,     0,     1, -9999, -9999, -9999, -9999]))
  </code></pre>
  
  <p>what's that <code>array([-9999,     0,     1, -9999, -9999, -9999, -9999])</code> ? Also, in the documentation, they talk about a sparse matrix not about an adjacency one. But an adjacency matrix seems to be a sparse matrix by definition so it's not clear for me. </p>