title: Python: How to iterate an n-dimensional matrix?
body: <p>I have a matrix with shape (1 , 255, 13, 13), so I have 13x13=169 elements and for each of this elements I have a array of 255 elements. </p>
  
  <p>I want to iterate over the fourth element of the 255 array and count how many elements are greater than 0.5.</p>
  
  <p>This code doesn't work but help to understand what I want:</p>
  
  <pre><code>out = net.forward()
  
  count1=0
  count2=0
  
  for i in out[0]:
      for j in out[2]:
          for a in out[3]:
              for b in out[1]:
                  if b[3]&gt; 0.5:
  
                      count1+=1
                  else:
                      count2+=1
  </code></pre>
  
  <p>What is the best way to do this?</p>