<div dir="ltr">I don't have strong feelings, but I would say yes to __imul__, no to __div__ and __floordiv__ (with str/list/tuple as the precedent).<div><br></div><div>For chisquare, I would be perfectly happy with:</div><div><br></div><div>digit_counts = Counter(...)</div><div>scipy.stats.chisquare(list(digit_counts.values()))</div></div><br><div class="gmail_quote"><div dir="ltr">On Sun, Apr 15, 2018 at 9:39 PM Raymond Hettinger <<a href="mailto:raymond.hettinger@gmail.com">raymond.hettinger@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
> On Apr 15, 2018, at 9:04 PM, Peter Norvig <<a href="mailto:peter@norvig.com" target="_blank">peter@norvig.com</a>> wrote:<br>
> <br>
> it would be a bit weird and disorienting for the arithmetic operators to have two different signatures:<br>
> <br>
>     <counter> += <counter><br>
>     <counter> -= <counter><br>
>     <counter> *= <scalar><br>
>     <counter> /= <scalar><br>
> <br>
> Is it weird and disorienting to have:<br>
> <br>
> <str> += <str><br>
> <str> *= <scalar> <br>
<br>
Yes, there is a precedent that does seem to have worked out well in practice :-)  It isn't exactly parallel because strings aren't containers of numbers, they don't have & and |, and there isn't a reason to want a / operation, but it does suggest that signature variation might not be problematic.  <br>
<br>
BTW, do you just want __mul__ and __rmul__?  If those went in, presumably there will be a request to support __imul__ because otherwise c*=3 would still work but would be inefficient (that was the rationale for adding inplace variants for all the current arithmetic operators). Likewise, presumably someone would legitimately want __div__ to support the normalization use case.  Perhaps less likely, there would be also be a request for __floordiv__ to allow exactly scaled results to stay in the domain of integers.  Which if any of these makes sense to you?<br>
<br>
Also, any thoughts on the cleanest way to express the computation of a chi-squared statistic (for example, to compare observed first digit frequencies to the frequencies predicted by Benford's Law)?  This isn't an arbitrary question (it came up when a professor first proposed a variant of this idea a few years ago).<br>
<br>
<br>
Raymond</blockquote></div>