title: All non-redundant paths in a directed graph (DiGraph) from NetworkX . Python
body: <p>I'm looking for a way to navigate directed graphs to find the building blocks of the graph. <code>NetworkX</code> has <code>all_simple_paths</code> that finds all paths between <code>source</code> and <code>target</code> nodes.  What I would like to do is similar, but to find not exactly the same.  <em>An unbiased decomposition of a network into minimal units</em> </p>
  
  <p>This directed network <code>H</code> below, is built on the following paths:</p>
  
  <pre><code>#Non-redundant paths
  ['A', 'B', 'C', 'E', 'F']
  ['A', 'B', 'D', 'E', 'F']
  ['G','C','E','F']
  </code></pre>
  
  <p><strong>What is the most efficient way in Python to find these paths?</strong> Would navigating through <code>nx.adjacency_matrix(H).toarray()</code> be the way to do it? </p>
  
  <p><a href="https://i.stack.imgur.com/uPX9m.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uPX9m.png" alt="enter image description here"></a></p>
  
  <pre><code>#!/usr/bin/python
  
  import networkx as nx
  import matplotlib.pyplot as plt
  
  %matplotlib inline
  
  H = nx.DiGraph()
  
  nodes = list("ABCDEFG")
  edges = [("A","B"),("B","C"),("B","D"),("C","E"),("D","E"),("E","F"),("G","C")]
  H.add_nodes_from(nodes)
  H.add_edges_from(edges)
  coords = {"A":(-2,0),"B":(-1,0),"C":(0,1),"D":(0,-1),"E":(1,0),"F":(2,0),"G":(0,2)}
  nx.draw(H,pos=coords,with_labels=True)
  
  paths = nx.all_simple_paths(H, source="A", target="F") 
  
  for path in paths: print(path)    
  #['A', 'B', 'C', 'E', 'F']
  #['A', 'B', 'D', 'E', 'F']
  </code></pre>