title: Map each value of a list to its weighted percentile
body: <p>I'd like to calculate the percentile of each value in a list (or numpy array), weighted by weights in another list. For example, given some <code>f</code> I'd like:</p>
  
  <pre><code>x = [1, 2, 3, 4]
  weights = [2, 2, 3, 3]
  f(x, weights)
  </code></pre>
  
  <p>to yield <code>[20, 40, 70, 100]</code>.</p>
  
  <p>I can calculate the unweighted percentile for a single item using</p>
  
  <pre><code>from scipy import stats
  stats.percentileofscore(x, 3)
  # 75.0
  </code></pre>
  
  <p>Per <a href="https://stackoverflow.com/questions/12414043/map-each-list-value-to-its-corresponding-percentile">Map each list value to its corresponding percentile</a> I can also calculate this for each using</p>
  
  <pre><code>[stats.percentileofscore(x, a, 'rank') for a in x]
  # [25.0, 50.0, 75.0, 100.0]
  </code></pre>
  
  <p>And per <a href="https://stackoverflow.com/questions/48252282/weighted-version-of-scipy-percentileofscore">Weighted version of scipy percentileofscore</a> I can calculate a single item's weighted percentile using:</p>
  
  <pre><code>def weighted_percentile_of_score(x, weights, score, kind='weak'):
      npx = np.array(x)
      npw = np.array(weights)
  
      if kind == 'rank':  # Equivalent to 'weak' since we have weights.
          kind = 'weak'
  
      if kind in ['strict', 'mean']:
          indx = npx &lt; score
          strict = 100 * sum(npw[indx]) / sum(weights)
      if kind == 'strict':
          return strict
  
      if kind in ['weak', 'mean']:    
          indx = npx &lt;= score
          weak = 100 * sum(npw[indx]) / sum(weights)
      if kind == 'weak':
          return weak
  
      if kind == 'mean':
          return (strict + weak) / 2
  </code></pre>
  
  <p>Called as:</p>
  
  <pre><code>weighted_percentile_of_score(x, weights, 3))  # 70.0 as desired.
  </code></pre>
  
  <p>How do I do this (efficiently) for each item in the list?</p>