http://blog.csdn.net/pipisorry/article/details/48770785

, , ]
, '\n')

输出:
True

当然可以设置度参数bias : int, optional来改变这种计算模式
Default normalization is by (N - 1), where N is the number of observations given (unbiased estimate). If bias is 1, then normalization is by N. These values can be overridden by using the keyword ddof in numpy versions >= 1.5.

, , normed=True)
bins ] :]) / 2
plt.plot(bins, cnts)

[matplotlib绘图实例 pyplot、pylab模块及作图参数:hist]

Note: lz建议使用seaborn.distplot()。

np.bincount()

对整数数组中各个元素出现的次数进行统计,它要求数组中所有元素都是非负的。其返回数组中第i个元素的值表示整数i在参数数组中出现的次数。
>>> np.bincount(a)
array([0, 2, 2, 0, 0, 1, 2, 1, 0, 2])
由上面的结果可知,在数组a中有两个1、两个2、一个5、两个6、一个7和两个9,而 0、3、4、8等数没有在数组a中出现。
当指定weights参数时,bincount(x, weights=w)返冋数组x中每个整数所对应的w中的权值之和。
>>> x =np.array([0 , 1, 2, 2, 1, 1, 0])
>>> w = np.array([0.1, 0.3, 0.2,0.4,0.5,0.8,1.2])
>>> np.bincount(x, w)
array ([ 1.3,1.6,0.6])
要求平均值:
>>> np.bincount(x,w)/np.bincount(x)
array([ 0.65 , 0.53333333, 0.3])

但是np.ndarray怎么统计数组每个元素出现的个数呢?

list.count(element)

只能先将np.array.tolist()转换成python list,再使用list的count方法计数某个元素出现次数。

>>> a = ['a', 'b', 'c', 3, '4', '2', '2', 2, 2]
>>> a.count(2)
2

[python入门教程、基础知识、基本类型的操作及转换]

[numpy-ref-1.8.1 : 3.30 Statistics p1256]

[numpy/reference/routines.statistics]

皮皮Blog

统计函数cov协方差矩阵计算示例

空间中有三个点,值得注意的是,这三个点是随机变量的观测值,而坐标系x,y(维度)是随机变量!也就是有N个点,这N个点就是观测值,而每个点有K维,K就是随机变量个数!!!

Consider two variables, x0 and x1, which correlate perfectly, but in opposite directions:
>>> x = np.array([[0, 2], [1, 1], [2, 0]]).T
>>> x
array([[0, 1, 2],
[2, 1, 0]])

Note how x0 increases while x1 decreases. The covariance matrix shows this clearly:
>>> np.cov(x)
array([[ 1., -1.],
[-1., 1.]])
Note that element C0;1, which shows the correlation between x0 and x1, is negative.

Further, note how x and y are combined:
>>> x = [-2.1, -1, 4.3]
>>> y = [3, 1.1, 0.12]
>>> X = np.vstack((x,y))
>>> print np.cov(X)
[[ 11.71 -4.286 ]
[ -4.286 2.14413333]]
>>> print np.cov(x, y)
[[ 11.71 -4.286 ]
[ -4.286 2.14413333]]
>>> print np.cov(x)
11.71
3.30.

Note:

1. 上面的X等价于np.array([[-2.1, -1, 4.3], [3, 1.1, 0.12]])

2.  从这里可以看出,cov函数的输入可以是矩阵(二维向量),计算的是矩阵中行向量(R.V.)间的协方差矩阵,其对角线上的元素分别是单个行向量(R.V.)的方差。所以如果初始数据[[0, 2], [1, 1], [2, 0]]是观测值要先转置再求协方差!

3. 矩阵的协方差矩阵的计算等价于单独将不同R.V.分量拿出来作为多个参数输入到cov函数中的协方差。

from: http://blog.csdn.net/pipisorry/article/details/48770785

ref:

最新文章

  1. String,StringBuffer,StringBuilder的区别
  2. 【BZOJ-4521】手机号码 数位DP
  3. linq to sql 增删改查
  4. onClick,onServerClick,onClientClick
  5. linux下sqlite3可视化工具
  6. Asp.net MVC1 学习1
  7. WampServer下如何实现多域名配置
  8. STM32开发指南-蜂鸣器实验
  9. MSSQL sql server order by 1,2 的具体含义
  10. C# 中使用 Excel
  11. mysql 开发进阶篇系列 28 数据库二进制包安装(centos系统准备)
  12. 配置Zookeper
  13. EZ 2018 05 04 NOIP2018 模拟赛(十二)
  14. linux第十八章学习笔记
  15. send和sendmsg性能测试
  16. Docker Compose 版本过高(Docker版本不匹配),降低docker-compose版本
  17. spark 将dataframe数据写入Hive分区表
  18. lisp base
  19. a7
  20. dalvik 基于 jvm 的改进

热门文章

  1. 用burpsuite暴力破解后台
  2. 小程序上拉下拉共存时不可使用scroll-view的解决方法
  3. JavaScript原型与原型链
  4. Android查缺补漏(线程篇)-- IntentService的源码浅析
  5. 再见,segmentfault
  6. 实验与作业(Python)-02 Python函数入门与温度转换程序
  7. C++格式化输出浮点数
  8. Launcher3 HotSeat显示名称
  9. 【mybatis深度历险系列】mybatis的框架原理+入门程序解析
  10. Android自定义控件及自定义属性