热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

使用Python来计算均值、中位数、标准差

计算一串数组的均值、中位数、标准差#!usrbinenvpython#-*-coding:utf-8-*-@author:FIGTHING@file:DataMining.py@f

计算一串数组的均值、中位数、标准差

#!/usr/bin/env python
#-*- coding:utf-8 -*-
'''
@author : FIGTHING
@file : DataMining.py
@function:
@software: Pycharm
@time : 2019/06/13/15:40
'''
import numpy as np
age = [23,23,27,27,39,41,47,49,50,52,54,54,56,57,58,58,61]
fat = [9.5,26.5,7.8,17.8,31.4,25.9,27.4,27.2,31.2,34.6,42.5,28.8,33.4,30.2,34.1,23.9,35.7]
#求均值
age_mean = np.mean(age)
print("age平均值为:%f" % age_mean)
fat_mean = np.mean(fat)
print("fat平均值为:%f" % fat_mean)
#求中位数
age.sort()
mid = int(len(age) / 2)
if len(age) % 2 == 0:
median = (age[mid-1] + age[mid]) / 2.0
else:
median = age[mid]
print("age中位数为:%f" % median)
fat.sort()
mid = int(len(fat) / 2)
if len(fat) % 2 == 0:
median = (fat[mid-1] + fat[mid]) / 2.0
else:
median = fat[mid]
print("fat中位数为:%f" % median)
#求标准差
age_std = np.std(age,ddof=1)
print("age标准差为:%f" % age_std)
fat_std = np.std(fat,ddof=1)
print("fat标准差为:%f" % fat_std)

"We often turn out to be our own worst enemy."--《 Wonder Wheel》


推荐阅读
author-avatar
平凡小迪
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有