title: Importing an array using Python
body: <p>I have an array <code>Pe</code> with dimensions <code>(2,3,3)</code>. I am importing Pe but then I want the code to calculate for each Pe and give me visited indices. Right now, I have to manually add <code>Pe.Pe[0]</code>,<code>Pe.Pe[1]</code> in the line <code>Visited_Indices,timestamps=iterate_array(0,0, Pe.Pe[0], lambda x : x &lt; 150)</code>. How do I implement <code>Pe.Pe[i]</code> where <code>i</code> goes from 0 to 1?</p>
  <p>Pe array is</p>
  <pre><code>import numpy as np
  Pe = np.array([[[128.22918457, 168.52413295, 209.72343319],
          [129.01598287, 179.03716051, 150.68633749],
          [131.00688309, 187.42601593, 193.68172751]],
  
         [[ 87.70103267, 115.2603484 , 143.4381863 ],
          [ 88.23915528, 122.45062554, 103.06037156],
          [ 89.60081102, 128.18809696, 132.46662659]]])
  print([Pe])
  </code></pre>
  <p>The code is</p>
  <pre><code>import numpy as np
  import time
  import Pe
  
  def get_neighbor_indices(position, dimensions):
      '''
      dimensions is a shape of np.array
      '''
      i, j = position
      indices = [(i+1,j), (i-1,j), (i,j+1), (i,j-1)]
      return [
          (i,j) for i,j in indices
          if i&gt;=0 and i&lt;dimensions[0]
              and j&gt;=0 and j&lt;dimensions[1]
          ]
  
  def iterate_array(init_i, init_j, arr, condition_func):
      '''
      arr is an instance of np.array
      condition_func is a function (value) =&gt; boolean
      '''
      indices_to_check = [(init_i,init_j)]
      checked_indices = set()
      result = []
      t0 = None
      t1 = None
      timestamps = []
      while indices_to_check:
          pos = indices_to_check.pop()
          if pos in checked_indices:
              continue
          item = arr[pos]
          checked_indices.add(pos)
          if condition_func(item):
              result.append(item)
              t1=time.time()
              if(t0==None):
                  t0=t1
              timestamps.append(t1-t0)
              indices_to_check.extend(
                  get_neighbor_indices(pos, arr.shape)
              )
      return result,timestamps
  
  
  Visited_Indices,timestamps=iterate_array(0,0, Pe.Pe[0], lambda x : x &lt; 150)
  out = list(zip(*np.where(np.isin(Pe, Visited_Indices))))
  print(&quot;Visited =&quot;,[Visited_Indices]) 
  </code></pre>