Dear all,

I have a long-standing PR (#9211 <https://github.com/numpy/numpy/pull/9211>)
about adding a "weights" option to the quantile/percentile methods' API.
The code is tested for all 13 different interpolation methods, and I
welcome any additional testing suggestions.

A couple of remarks:

1.) weights can be any positive real number, and there's no distinction
between frequency weights and probability weights.  Underneath, along the
data axis you're applying weights to, if any weight is less than 1, then
the code will renormalize the weights such that the minimum is 1.

For example, if weights=[0.1, 0.9], then the quantiles will be computed as
if weights=[1, 9].  If weights=[0.25, 0.75], then they'll be treated as if
weights=[1, 3].  In other words, probability weights are converted to
frequency weights for the calculation.

If another function using quantile() wants to make that distinction between
frequency/probability weights in its API, it is free to do so.  But right
now I do not see any reason for it in quantile()/percentile().

2.) The use of np.vectorize().  In computing quantiles, it's necessary to
sort the data values along the data axis, and rearrange the corresponding
weights according to the sort order.  Hence each column down the data axis
has a different rearrangement.  vectorize() allows for such synchronized
operations between equal-shaped arrays.  I don't see that from, say,
apply_along_axis().

Lastly, I'll be sure to add more docs/comments to better explain the steps
in the code.

Best,

Chun
_______________________________________________
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com

Reply via email to