title: What is wrong with my function? Finding the shortest path using numpy and networkx
body: <p>so I'm creating a code to calculate the shortest path using networkx. I created a 3D array using numpy and then calculated the shortest path like this:</p>
  
  <pre><code>import numpy as np
  import networkx as nx
  
  arr = np.random.randint(1, 100, size = (2, 5, 5)) #3D array
  
  for i in arr:
      graph = nx.from_numpy_array(i, create_using = nx.DiGraph)
      path = nx.shortest_path(graph, 0, 3, weight = 'weight')
      print(path)
  
  </code></pre>
  
  <p>Since I'm using two matrix, I got the next output:</p>
  
  <pre><code>[0, 1, 3] #path1
  [0, 3]    #path2
  </code></pre>
  
  <p>After that I decided to create a function to do the exact same thing, like this:</p>
  
  <pre><code>import numpy as np
  import networkx as nx
  
  arr = np.random.randint(1, 100, size = (2, 5, 5)) #3D array
  
  
  def shortest(prices):
  
      for i in arr:
          graph = nx.from_numpy_array(i, create_using = nx.DiGraph)
          path = nx.shortest_path(graph, 0, 3, weight = 'weight')
          return path
  
  print(shortest(arr))
  </code></pre>
  
  <p>and I got the next output:</p>
  
  <pre><code>[0, 1, 3] #same as path 1
  </code></pre>
  
  <p>And if I if change the position of the "return path" like this:</p>
  
  <pre><code>def shortest(precios):
  
      for i in arr:
          graph = nx.from_numpy_array(i, create_using = nx.DiGraph)
          path = nx.shortest_path(graph, 0, 3, weight = 'weight')
      return path
  
  print(shortest(arr))
  </code></pre>
  
  <p>I got the next output:</p>
  
  <pre><code>[0, 3] #same as path 2
  </code></pre>
  
  <p>I can't get the the two paths in the same output using my function. Any idea what is happening here? I was practicing using functions in python since I'm kinda new in the topic, so I was hoping you can help me seeing what is wrong? Thank you!</p>