如何在Scipy中计算稀疏矩阵的一列的方差? [英] How do I compute the variance of a column of a sparse matrix in Scipy?

查看:105
本文介绍了如何在Scipy中计算稀疏矩阵的一列的方差?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大的scipy.sparse.csc_matrix,并想将其标准化.也就是说,从每个元素中减去列平均值,然后除以列标准偏差(std)i.

I have a large scipy.sparse.csc_matrix and would like to normalize it. That is subtract the column mean from each element and divide by the column standard deviation (std)i.

scipy.sparse.csc_matrix具有.mean(),但是有一种有效的方法来计算方差或标准差吗?

scipy.sparse.csc_matrix has a .mean() but is there an efficient way to compute the variance or std?

推荐答案

您可以使用均值来自己计算方差,并使用以下

You can calculate the variance yourself using the mean, with the following formula:

E[X^2] - (E[X])^2

E[X]代表平均值.因此,要计算E[X^2],您必须将csc_matrix平方,然后使用mean函数.要获得(E[X])^2,您只需要对使用常规输入获得的mean函数的结果求平方即可.

E[X] stands for the mean. So to calculate E[X^2] you would have to square the csc_matrix and then use the mean function. To get (E[X])^2 you simply need to square the result of the mean function obtained using the normal input.

这篇关于如何在Scipy中计算稀疏矩阵的一列的方差?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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