title: Python: Weighted coefficient of variation
body: <p>How can I calculate the <strong>weighted <a href="https://en.wikipedia.org/wiki/Coefficient_of_variation" rel="nofollow noreferrer">coefficient of variation</a></strong> (CV) over a NumPy array in Python? It's okay to use any popular third-party Python package for this purpose.</p>
  
  <p>I can calculate the CV using <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.variation.html#scipy.stats.variation" rel="nofollow noreferrer"><code>scipy.stats.variation</code></a>, but it's not weighted.</p>
  
  <pre><code>import numpy as np
  from scipy.stats import variation
  
  arr = np.arange(-5, 5)
  weights = np.arange(9, -1, -1)  # Same size as arr
  cv = abs(variation(arr))  # Isn't weighted
  </code></pre>