title: Python: Complex for-loops
body: <p>I am working through some code trying to understand some Python mechanics, which I just do not get. I guess it is pretty simple and I also now, what it does, but i do not know how it works. I understand the normal use of <code>for</code>-loops but this here... I do not know. </p>
  
  <p>Remark: I know some Python, but I am not an expert. </p>
  
  <pre><code>np.array([[[S[i,j]] for i in range(order+1)] for j in range(order+1)])
  </code></pre>
  
  <p>The second piece of code, I have problems with is this one: </p>
  
  <pre><code>for i in range(len(u)):
          for j in range(len(v)):
              tmp+=[rm[i,j][k]*someFuction(name,u[i],v[j])[k] for k in range(len(rm[i,j])) if rm[i,j][k]]
  </code></pre>
  
  <p>How does the innermost <code>for</code>-loop work? And also what does the <code>if</code> do here?</p>
  
  <p>Thank you for your help. </p>
  
  <p>EDIT: Sorry that the code is so unreadable, I just try to understand it myself. <code>S, rm</code> are numpy matrices, <code>someFunction</code> returns an array with scalar entries, and<code>tmp</code> is just a help variable</p>