title: How do I get column wise relative error between multidimensional array?
body: <p>I have a function which takes an 2 arrays, a array of model predictions and an array of true values. It works fine when dealing with 1d arrays, but I need to adjust it for multidimensional arrays. I would like to compute my <code>threshold_acc</code> again but this time  for each column. How do I go about this?</p>
  <p><code>threshold_acc</code> which represents the proportion of set with error below the specified threshold.
  Also do I need to change my threshold to change my threshold to <code>+-</code> since I've started seeing negative values in the multidimensional array or is there a better error measure I could use?</p>
  <pre><code>import numpy as np
  import pandas as pd 
  
  # sample data
  np.random.seed(20)
  dd = np.random.uniform(low=-20., high=20, size=(25, 4))
  dp = np.random.uniform(low=5, high=25, size=(25, 4))
  
  data = [dd, dp]
  
  def inference( dummy_data, error_threshold=10):
      rel_err_list = []
      AE_error_list = []
      mse_list = []
      input_var = []
      true_var =[]
      pred_var = []
      
      n_correct = 0; n_wrong = 0; n_inf =0
      # Iterate through data loader and inference and evaluate data
      targets, outputs = data[0], data[1]
      for idx, (outputs, targets) in enumerate(zip(outputs, targets)):
  
          rel_error = np.abs(outputs- targets )/targets
          rel_error = rel_error * 100
          AE_error = np.abs(outputs- targets )
          
          if np.isfinite(rel_error).all():
              rel_err_list.append(rel_error)
              AE_error_list.append(AE_error)
  
              # Negative errors
              print(f&quot;error: {rel_error} output: {outputs}  target: {targets}&quot;)
          else: n_inf +=1
          if rel_error.all() &lt; error_threshold:
              n_correct +=1 
          else: n_wrong += 1 
  
          true_var.append(targets)
          pred_var.append(outputs)
       
              
            
      median_err, max_err, min_err = np.median(rel_err_list),  np.max(rel_err_list), np.min(rel_err_list)
      threshold_acc = ((n_correct * 1.0) / 25) * 100
      true_var = np.array(true_var)
      pred_var = np.array(pred_var)
      err_var = np.array(rel_err_list)
      AE_var = np.array(AE_error_list)
    
      true_var = np.reshape(true_var, dummy_data[0].shape)
      pred_var = np.reshape(pred_var, dummy_data[0].shape)
      err_var = np.reshape(err_var, dummy_data[0].shape)
      AE_var = np.reshape(AE_var, dummy_data[0].shape) 
      
      results = np.concatenate([true_var, pred_var, err_var, AE_var], axis=1)
  
      results_df  = pd.DataFrame(results)          
      return median_err, max_err, min_err, threshold_acc, n_inf, n_wrong, results_df, pred_var
  
  dd = np.random.uniform(low=1., high=20, size=(25, 1))
  dp = np.random.uniform(low=5, high=25, size=(25, 1))
  median_err, max_err, min_err, threshold_acc, n_inf, n_wrong, results_df, pred_var = inference(data, 10)
  print(f&quot;\nAverage relative error over valid predictions : {median_err:.3f} \nMax error over valid predictions : {max_err:.3f} \nMin error over valid predictions : {min_err:.3f}\nProportion of test set with accuracy over 90%: {threshold_acc:.3f}\n\n\
  {n_inf} null predictions \n{n_wrong} incorrect (&lt;90%) predictions \n{n_inf+n_wrong} null or incorrect predictions out of 25&quot;)
  
  
  median_err, max_err, min_err, threshold_acc, n_inf, n_wrong, results_df, pred_var = inference(data, 10)
  print(f&quot;\nAverage relative error over valid predictions : {median_err:.3f} \nMax error over valid predictions : {max_err:.3f} \nMin error over valid predictions : {min_err:.3f}\nProportion of test set with accuracy over 90%: {threshold_acc:.3f}\n\n\
  {n_inf} null predictions \n{n_wrong} incorrect (&lt;90%) predictions \n{n_inf+n_wrong} null or incorrect predictions out of 25&quot;)
  </code></pre>