Steven D'Aprano <steve+pyt...@pearwood.info> added the comment:

Thanks Warren, the resistance example is excellent, would you like to write up 
a PR to add it to the docs?

In the original design, I prohibited negative numbers because that seems to be 
what everyone says you should do, but as far as I can tell it is mathematically 
well defined so long as the sum of positive values doesn't equal the sum of 
negative values. And in that case, we could return a NAN.

I don't know that there's any physical meaning to the harmonic mean of negative 
values (circuits with negative resistances?), but I'm almost tempted to make 
this "consenting adults" and remove the restriction altogether. That would 
simplify the implementation and remove any arguments about early-out on zero.

I acknowledge Warren's point about permutations of data, but that applies to 
anything with an early-out. I don't think that's quite persuasive enough to 
justify losing the early exit on zero.

Warren, if you feel really strongly about this, feel free to try to change my 
mind. But for now, I think that documenting that zero triggers an early-out is 
the right solution.

By the way, I've just noticed that harmonic_mean([INF, INF]) raises. Should it 
return INF instead?

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue38382>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to