python之np.var()函数解析

np.var()函数:

def var(a, axis=None, dtype=None, out=None, ddof=0, keepdims=np._NoValue):

axis : None or int or tuple of ints, optional
        Axis or axes along which the variance is computed.  The default is to
        compute the variance of the flattened array.

这里说明axis值为整数或元组(类似于(1,2,3))这种
对于二维矩阵,axis的值可以是0也可以是1,其中axis=0表示按列求平均,当axis=1表示按行求平均,未给出axis则表示将所有元素加起来求平均。

dataset = [
        [1.658985, 4.285136, -3.453687, 3.424321, 4.838138, -1.151539, -5.379713, -3.362104, 0.972564, 2.924086],
        [-3.567919, 1.531611, 0.450614, -3.302219, -3.487105, -1.724432, 2.668759, 1.594842, -3.156485, 3.191137],
        [3.165506, -3.999838, -2.786837, -3.099354, 4.208187, 2.984927, -2.123337, 2.943366, 0.704199, -0.479481],
        [-0.39237, -3.963704, 2.831667, 1.574018, -0.790153, 3.343144, 2.943496, -3.357075, -3.195883, -2.283926],
        [2.336445, 2.875106, -1.786345, 2.554248, 2.190101, -1.90602, -3.403367, -2.778288, 1.778124, 3.880832],
        [-1.688346, 2.230267, 2.592976, -2.054368, -4.007257, -3.207066, 2.257734, 3.387564, -2.679011, 0.785119],
        [0.939512, -4.023563, -3.674424, -2.261084, 2.046259, 2.735279, -3.18947, 1.780269, 4.372646, -0.822248]]

print(var(dataset,axis=0))
输出结果:
[  4.85572291  11.66931904   6.64039908   7.02010573  10.76766748
   6.51731034  10.0788433    8.01974819   7.26723794   4.73381655]

print(var(dataset,axis=1))
输出结果:
[ 11.69812548   6.77643084   8.36777452   7.2442908    6.6098529
   6.89108237   8.0053096 ]

print(var(dataset))
输出结果:
8.10196690528

更多技术干货请关注:
这里写图片描述

评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

脑机接口社区

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值