问题
This is what I have right now. It just finds the median with an odd amount of numbers.
def median(height):
height.sort()
x = len(height)
x -= 1
posn = x // 2
return height[posn]
回答1:
"The median is the numeric value separating the higher half of a sample data set from the lower half. The median of a data set can be found by arranging all the values from lowest to highest value and picking the one in the middle. If there is an odd number of data values then the median will be the value in the middle. If there is an even number of data values the median is the mean of the two data values in the middle." - Source
For the data set 1, 1, 2, 5, 6, 6, 9
the median is 5
.
For the data set 1, 1, 2, 6, 6, 9
the median is 4
. It is the mean of 2
and 6
or, (2+6)/2 = 4
.
来源:https://stackoverflow.com/questions/34299332/how-can-i-find-median-with-an-even-amount-of-numbers-in-a-list