title: Turn MATLAB code into Python
body: <p>I am a newbie in Python so I am in trouble with vectorized operations and indexing in Python. I completely understand how to rewrite it in C - style with element-by-element computation, but it wouldn't be "pythonic" and laconic as MATLAB code. I want it be short and laconic. I need to translate the next code from MATLAB into Python:</p>
  
  <pre><code>for t=2:size(cl, 1)
      hasData=find(isfinite(retGap(t, :)) &amp; op(t, :) &lt; buyPrice(t, :) &amp; op(t, :) &gt; ma(t, :));
      [foo idxSort]=sort(retGap(t, hasData), 'ascend');
      positionTable(t, hasData(idxSort(1:min(topN, length(idxSort)))))=1;
  end
  </code></pre>
  
  <p>All of the arrays are 1500x497 floats. I can translate the first line like this:</p>
  
  <pre><code>posCl = cl.iloc[t]
  posOp = op.iloc[t]
  posBp = buyPrice.iloc[t]
  posMa = ma.iloc[t]
  posRg = retGap.iloc[t]
  posRg[pd.notnull(posRg) &amp; (posOp &lt; posBp) &amp; (posOp &gt; posMa)]
  </code></pre>
  
  <p>But I have no idea how to translate the lines with sorting in a laconic way.</p>