mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Some reformatting (suggested by Black) and minor factoring. (GH-20865)
This commit is contained in:
parent
d71ab4f738
commit
5aad027db9
1 changed files with 29 additions and 31 deletions
|
@ -554,8 +554,7 @@ def mode(data):
|
||||||
If *data* is empty, ``mode``, raises StatisticsError.
|
If *data* is empty, ``mode``, raises StatisticsError.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
data = iter(data)
|
pairs = Counter(iter(data)).most_common(1)
|
||||||
pairs = Counter(data).most_common(1)
|
|
||||||
try:
|
try:
|
||||||
return pairs[0][0]
|
return pairs[0][0]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
|
@ -597,7 +596,7 @@ def multimode(data):
|
||||||
# For sample data where there is a positive probability for values
|
# For sample data where there is a positive probability for values
|
||||||
# beyond the range of the data, the R6 exclusive method is a
|
# beyond the range of the data, the R6 exclusive method is a
|
||||||
# reasonable choice. Consider a random sample of nine values from a
|
# reasonable choice. Consider a random sample of nine values from a
|
||||||
# population with a uniform distribution from 0.0 to 100.0. The
|
# population with a uniform distribution from 0.0 to 1.0. The
|
||||||
# distribution of the third ranked sample point is described by
|
# distribution of the third ranked sample point is described by
|
||||||
# betavariate(alpha=3, beta=7) which has mode=0.250, median=0.286, and
|
# betavariate(alpha=3, beta=7) which has mode=0.250, median=0.286, and
|
||||||
# mean=0.300. Only the latter (which corresponds with R6) gives the
|
# mean=0.300. Only the latter (which corresponds with R6) gives the
|
||||||
|
@ -643,8 +642,7 @@ def quantiles(data, *, n=4, method='exclusive'):
|
||||||
m = ld - 1
|
m = ld - 1
|
||||||
result = []
|
result = []
|
||||||
for i in range(1, n):
|
for i in range(1, n):
|
||||||
j = i * m // n
|
j, delta = divmod(i * m, n)
|
||||||
delta = i*m - j*n
|
|
||||||
interpolated = (data[j] * (n - delta) + data[j + 1] * delta) / n
|
interpolated = (data[j] * (n - delta) + data[j + 1] * delta) / n
|
||||||
result.append(interpolated)
|
result.append(interpolated)
|
||||||
return result
|
return result
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue