<br><br>On Monday, April 16, 2018, Raymond Hettinger <<a href="mailto:raymond.hettinger@gmail.com">raymond.hettinger@gmail.com</a>> wrote:<br><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">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).</blockquote><div><br></div><div><div><br></div><div><a href="https://en.wikipedia.org/wiki/Chi-squared_distribution">https://en.wikipedia.org/wiki/Chi-squared_distribution</a></div><div><a href="https://en.wikipedia.org/wiki/Chi-squared_test">https://en.wikipedia.org/wiki/Chi-squared_test</a></div><div><a href="https://en.wikipedia.org/wiki/Benford%27s_law">https://en.wikipedia.org/wiki/Benford%27s_law</a></div><div>(How might one test this with e.g. *double* SHA256?)</div><div><br></div><div>proportions_chisquare(count, nobs, value=None)</div><div><a href="https://www.statsmodels.org/dev/generated/statsmodels.stats.proportion.proportions_chisquare.html">https://www.statsmodels.org/dev/generated/statsmodels.stats.proportion.proportions_chisquare.html</a></div><div><br></div><div><a href="https://www.statsmodels.org/dev/genindex.html?highlight=chi">https://www.statsmodels.org/dev/genindex.html?highlight=chi</a></div><div><br></div><div><br></div><div>scipy.stats.chisquare(f_obs, f_exp=None, ddof=0, axis=0)</div><div><a href="https://docs.scipy.org/doc/scipy-0.18.1/reference/generated/scipy.stats.chisquare.html">https://docs.scipy.org/doc/scipy-0.18.1/reference/generated/scipy.stats.chisquare.html</a></div><div><br></div><div><br></div><div>sklearn.feature_selection.chi2(X, y)</div><div><a href="http://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.chi2.html#sklearn.feature_selection.chi2">http://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.chi2.html#sklearn.feature_selection.chi2</a></div><div><br></div><div>kernel_approximation.AdditiveChi2Sampler</div><div>kernel_approximation.SkewedChi2Sampler</div><div><a href="http://scikit-learn.org/stable/modules/classes.html#module-sklearn.kernel_approximation">http://scikit-learn.org/stable/modules/classes.html#module-sklearn.kernel_approximation</a> has</div><div><br></div><div>sklearn.metrics.pairwise.chi2_kernel(X, Y=None, gamma=1.0)</div><div><a href="http://scikit-learn.org/stable/modules/generated/sklearn.metrics.pairwise.chi2_kernel.html#sklearn.metrics.pairwise.chi2_kernel">http://scikit-learn.org/stable/modules/generated/sklearn.metrics.pairwise.chi2_kernel.html#sklearn.metrics.pairwise.chi2_kernel</a></div><div><br></div><div>sklearn.metrics.pairwise.additive_chi2_kernel(X, Y=None)</div><div><a href="http://scikit-learn.org/stable/modules/generated/sklearn.metrics.pairwise.additive_chi2_kernel.html#sklearn.metrics.pairwise.additive_chi2_kernel">http://scikit-learn.org/stable/modules/generated/sklearn.metrics.pairwise.additive_chi2_kernel.html#sklearn.metrics.pairwise.additive_chi2_kernel</a></div><div><br></div><div>...</div><div><br></div><div>FreqDist(collections.Counter(odict)) ... sparse-coding ... One-Hot / Binarization</div><div><a href="http://contrib.scikit-learn.org/categorical-encoding/">http://contrib.scikit-learn.org/categorical-encoding/</a></div><div><br></div><div><br></div><div>StandardScalar (for standardization) refuses to work with sparse matrices:</div><div><a href="http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.StandardScaler.html#sklearn.preprocessing.StandardScaler">http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.StandardScaler.html#sklearn.preprocessing.StandardScaler</a></div><div><br></div></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
Raymond<br>
______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br>
</blockquote>