numpy协方差矩阵numpy.cov [英] Numpy Covariance Matrix numpy.cov

查看:398
本文介绍了numpy协方差矩阵numpy.cov的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用numpy并想计算ndarray的协方差矩阵.我正在尝试使用numpy.cov(),但没有得到正确的结果.下面有更多详细信息.

I am using numpy and want to compute the covariance matrix for an ndarray. I am trying to use numpy.cov() but am not getting the correct results. More details below.

我的ndarray是768x8,其中8是我的数据集中的数字特征.

My ndarray is 768x8 for where 8 is the numbers features in my data set.

当我使用MATLAB计算协方差矩阵时,得到的是8x8(这是我所需要的),但是当我使用np.cov()时,得到的是768x768,这是不正确的.我尝试将rowvar参数更改为true,这是行不通的.

When I use MATLAB to compute the covariance matrix, I get a 8x8 (which is what I require), but when I use np.cov(), I get a 768x768 which is incorrect. I tried changing the rowvar argument to true and this does not work.

对numpy.cov()的正确调用是什么?换句话说,我该如何使用numpy从MATLAB中重现cov()结果.

What would be the correct call to numpy.cov()? In other words, how would I reproduce the cov() results from MATLAB using numpy.

推荐答案

令人惊讶的是,文档可能会告诉您.您应该传递rowvar=False来指示列代表变量.

Amazingly, the documentation might tell you. You should pass rowvar=False to indicate that columns represent variables.

>>> data.shape
(768, 8)
>>> numpy.cov(data, rowvar=False).shape
(8, 8)

这篇关于numpy协方差矩阵numpy.cov的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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