如何在列表中找到具有偶数个数字的中位数? [英] How can I find median with an even amount of numbers in a list?

查看:44
本文介绍了如何在列表中找到具有偶数个数字的中位数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我现在所拥有的.它只是找到带有奇数数字的中位数.

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]

推荐答案

中位数是将样本数据集的上半部分与下半部分分开的数值.从最低到最高的值,然后在中间选择一个.如果数据值的数量为奇数,则中位数为中间的值.如果数据值的数量为偶数,则中位数为中间两个数据值的平均值."-来源

"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

对于数据集 1、1,2、5、6、6、9 ,中位数为 5 .

For the data set 1, 1, 2, 5, 6, 6, 9 the median is 5.

对于数据集 1、1、2、6、6、9 ,中位数为 4 .它是 26 的平均值,或者,(2+6)/2 = 4.

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.

这篇关于如何在列表中找到具有偶数个数字的中位数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆