在PCA中会用到,记录一下
numpy.cov()的作用是计算协方差矩阵,下面给出几个例子
- >>> x = np.array([[0, 2], [1, 1], [2, 0]]).T
- >>> x
- array([[0, 1, 2],
- [2, 1, 0]])
- >>> np.cov(x)
- array([[ 1., -1.],
- [-1., 1.]])
- >>> 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
官方文档:http://docs.scipy.org/doc/numpy/reference/generated/numpy.cov.html