title: how to apply a generic function over numpy rows?
body: <p>Before you flag this as duplicate, let me explain to you that I read <a href="https://stackoverflow.com/questions/16468717/iterating-over-numpy-matrix-rows-to-apply-a-function-each">this page</a> and many others and I still haven't found a solution to my problem.</p>
  
  <p>This is the problem I'm having: given two 2D arrays, I want to apply a function F over the two arrays. F takes as input two 1D arrays.</p>
  
  <pre><code>import numpy as np
  a = np.arange(15).reshape([3,5])
  b = np.arange(30, step=2).reshape([3,5])
  
  # what is the 'numpy' equivalent of the following?
  np.array([np.dot(x,y) for x,y in zip(a,b)])
  </code></pre>
  
  <p>Please note that <code>np.dot</code> is just for demonstration. The real question here is any generic function F that works over two sets of 1D arrays.</p>
  
  <ul>
  <li>vectorizing either fails outright with an error or it applies the function element-by-element, instead of array-by-array (or row-by-row)</li>
  <li><code>np.apply_along_axis</code> applies the function iteratively; for example, using the variables defined above, it does <code>F(a[0], b[0])</code> and combines this with <code>F(a[0], b[1])</code> and <code>F(a[0], b[2])</code>. This is not what I'm looking for. Ideally, I would want it to stop at just <code>F(a[0], b[0])</code></li>
  <li>index slicing / advanced slicing doesn't do what I would like either. For one, if I do something like <code>np.dot(a[np.arange(3)], b[np.arange(3)])</code> this throws a ValueError saying that shapes (3,5) and (3,5) are not aligned. I don't know how to fix this.</li>
  </ul>
  
  <p>I tried to solve this in any way I could, but the only solution I've come up with that works is using list comprehension. But I'm worried about the cost to performance as a result of using list comprehension. I would like to achieve the same effect using a numpy operation, if possible. How do I do this?</p>