title: How to replace certain rows in numpy if they are better according to a self-specified function?
body: <p>I have a matrix x, and a matrix p of the same structure and size.
  One row represents the coordinates of an n-dimensional point.
  I have a function f which takes a point (a row so to say) and computes a score for it.</p>
  
  <p>Given x and p, I'd like to replace row i in p with row i in x if row i in x is smaller than row i in p according to my function f, formally:</p>
  
  <p>for all row indices i do:
      p[i] = (x[i] if f(x[i]) &lt; f(p[i]) else p[i])</p>
  
  <p>Python's list comprehension is way to slow, so I need to do it in numpy, but I'm new to numpy and have tried and failed hard while trying to figure it out.
  From other computations I already have, I've called them benchmarks for some reason, vectors for x and p where the value at index i is the score of row i.</p>
  
  <p>Here's the relevant code:</p>
  
  <pre><code>benchmark_x = FUNCTION(x)
  benchmark_p = FUNCTION(p)
  
  # TODO Too slow, ask smart guys from StackOverflow
  p = np.array([x[i] if benchmark_x[i] &lt; benchmark_p[i] else p[i] for i in range(p.shape[0])])
  </code></pre>