title: python find connected components in a 3D graph / tuple with three elements?
body: <p>I have a binary 3D numpy array, for which I would like to find connected components, i.d. neighbor elements with value 1. </p>
  
  <pre><code>data = np.random.binomial(1, 0.4, 1000)
  data = data.reshape((10,10,10))
  </code></pre>
  
  <p>Alternatively I can get the coordinates for each element with value one and get a set of lists with three elements for which I could get neighboring clusters</p>
  
  <pre><code>coordinates = np.argwhere(data &gt; 0)
  
  connected_elements = []
  for node in coordinates:
    neighbors = #Get possible neighbors of node
    if neighbors not in connected_elements:
      connected_elements.append(node)
    else:
      connected_elements.index(neighbor).extend(node)
  </code></pre>
  
  <p>How can I do this, or implement a 2D connected_components function for a 3D setting?</p>