title: How to optimize MAPE code in Python?
body: <p>I need to have a MAPE function, however I was not able to find it in standard packages ... Below, my implementation of this function.</p>
  
  <pre><code>def mape(actual, predict): 
      tmp, n = 0.0, 0
      for i in range(0, len(actual)):
          if actual[i] &lt;&gt; 0:
              tmp += math.fabs(actual[i]-predict[i])/actual[i]
              n += 1
      return (tmp/n)
  </code></pre>
  
  <p>I don't like it, it's super not optimal in terms of speed. How to rewrite the code to be more Pythonic way and boost the speed?</p>