title: Using vectorize to apply function to each row in Numpy 2d array
body: <p>I have a 1000x784 matrix of data (10000 examples and 784 features) called <code>X_valid</code> and I'd like to apply the following function to each row in this matrix and get the numerical result:</p>
  
  <pre><code>def predict_prob(x_valid, cov, mean, prior):
      return -0.5 * (x_valid.T.dot(np.linalg.inv(cov)).dot(x_valid) + mean.T.dot(
      np.linalg.inv(cov)).dot(mean) + np.linalg.slogdet(cov)[1]) + np.log(
      prior)
  </code></pre>
  
  <p>(<code>x_valid</code> is simply a row of data). I'm using numpy's <code>vectorize</code> to do this with the following code:</p>
  
  <pre><code>v_predict_prob = np.vectorize(predict_prob)
  scores = v_predict_prob(X_valid, covariance[num], means[num], priors[num])
  </code></pre>
  
  <p>(<code>covariance[num]</code>, <code>means[num]</code>, and <code>priors[num]</code> are just constants.)</p>
  
  <p>However, I get the following error when running this:</p>
  
  <pre><code>File "problem_5.py", line 48, in predict_prob
  return -0.5 * (x_valid.T.dot(np.linalg.inv(cov)).dot(x_valid) + mean.T.dot(np.linalg.inv(cov)).dot(mean) + np.linalg.slogdet(cov)[1]) + np.log(prior)
  AttributeError: 'numpy.float64' object has no attribute 'dot'
  </code></pre>
  
  <p>That is, it's not passing in each row of the matrix individually. Instead, it is passing in each entry of the matrix (not what I want).</p>
  
  <p>How can I alter this to get the desired behavior?</p>