title: How to aply mean_squared_error over a 3D array
body: <p>I am building a penalized regression model with 2 parameters $\lambda$ and $\alpha$. I am trying to find optimal values for these parameters so I consider a grid of different values. Let's say I consider <code>n_lambda</code> different $\lambda$ values and <code>n_alpha</code> different $\alpha$ values. In order to test the performance of the model, I consider $n$ data observations, for which I have the true value of my response vartiable, and I compute the predictions for these observations for each parameters pair.</p>
  
  <p>I store my predictions into a 3D-array matrix with dimension <code>(n_lambda, n_alpha, n_observations)</code>. This means that element <code>[0, 0, :]</code> of this matrix contains the predictions for n observations for the first value of $\lambda$ and the first value of $\alpha$.</p>
  
  <p>Now I want to compute, for each of my predictions, the means squared error. I know I can do this using nested for loops like:</p>
  
  <pre><code>from sklearn.metrics import mean_squared_error
  error_matrix = np.zeros(n_lambda, n_alpha)
  for i in range(n_lambda):
      for j in range(n_alpha):
          error_matrix[i, j] = mean_squared_error(true_value, prediction[i, j, :])
  </code></pre>
  
  <p>This would work, but nesting for loops is not really optimal. I guess there must be a better way to get what I want. Actually I have tried using <code>map</code> function but it is not working so I would appreciate any advice.</p>