[Python-checkins] Update nonstandard variable names (GH-26540)

rhettinger webhook-mailer at python.org
Fri Jun 4 19:28:41 EDT 2021


https://github.com/python/cpython/commit/3668e118f77c4e53167b75352c53674e758e1877
commit: 3668e118f77c4e53167b75352c53674e758e1877
branch: main
author: Raymond Hettinger <rhettinger at users.noreply.github.com>
committer: rhettinger <rhettinger at users.noreply.github.com>
date: 2021-06-04T16:28:31-07:00
summary:

Update nonstandard variable names (GH-26540)

files:
M Lib/statistics.py

diff --git a/Lib/statistics.py b/Lib/statistics.py
index 26009b0cbe430..1314095332a15 100644
--- a/Lib/statistics.py
+++ b/Lib/statistics.py
@@ -924,10 +924,10 @@ def correlation(x, y, /):
     xbar = fsum(x) / n
     ybar = fsum(y) / n
     sxy = fsum((xi - xbar) * (yi - ybar) for xi, yi in zip(x, y))
-    s2x = fsum((xi - xbar) ** 2.0 for xi in x)
-    s2y = fsum((yi - ybar) ** 2.0 for yi in y)
+    sxx = fsum((xi - xbar) ** 2.0 for xi in x)
+    syy = fsum((yi - ybar) ** 2.0 for yi in y)
     try:
-        return sxy / sqrt(s2x * s2y)
+        return sxy / sqrt(sxx * syy)
     except ZeroDivisionError:
         raise StatisticsError('at least one of the inputs is constant')
 
@@ -968,9 +968,9 @@ def linear_regression(x, y, /):
     xbar = fsum(x) / n
     ybar = fsum(y) / n
     sxy = fsum((xi - xbar) * (yi - ybar) for xi, yi in zip(x, y))
-    s2x = fsum((xi - xbar) ** 2.0 for xi in x)
+    sxx = fsum((xi - xbar) ** 2.0 for xi in x)
     try:
-        slope = sxy / s2x   # equivalent to:  covariance(x, y) / variance(x)
+        slope = sxy / sxx   # equivalent to:  covariance(x, y) / variance(x)
     except ZeroDivisionError:
         raise StatisticsError('x is constant')
     intercept = ybar - slope * xbar



More information about the Python-checkins mailing list