MCPcopy Index your code
hub / github.com/python/cpython / median

Function median

Lib/statistics.py:327–348  ·  view source on GitHub ↗

Return the median (middle value) of numeric data. When the number of data points is odd, return the middle data point. When the number of data points is even, the median is interpolated by taking the average of the two middle values: >>> median([1, 3, 5]) 3 >>> median([1, 3

(data)

Source from the content-addressed store, hash-verified

325
326
327def median(data):
328 """Return the median (middle value) of numeric data.
329
330 When the number of data points is odd, return the middle data point.
331 When the number of data points is even, the median is interpolated by
332 taking the average of the two middle values:
333
334 >>> median([1, 3, 5])
335 3
336 >>> median([1, 3, 5, 7])
337 4.0
338
339 """
340 data = sorted(data)
341 n = len(data)
342 if n == 0:
343 raise StatisticsError("no median for empty data")
344 if n % 2 == 1:
345 return data[n // 2]
346 else:
347 i = n // 2
348 return (data[i - 1] + data[i]) / 2
349
350
351def median_low(data):

Calls 1

StatisticsErrorClass · 0.85

Used in the wild real call sites across dependent graphs

searching dependent graphs…