Using NumPy's weighted average, I expected an element with infinite weighting to dominate the result, but instead it returns NaN,
>>> np.average([1,2], weights=[np.inf, 1])
nan
Was this an intentional design? It seems counter-intuitive.
EDIT: here's a more simple example:
>>> np.average([1], weights=[np.inf])
nan
Though not intentional, it is mathematically correct.
You end up with a formula like infinity/infinity. The result depends on which infinitiy is larger. And that is nonsense.
You need concrete numbers as weights, so you could use very large ones.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With