如何在numpy中的索引处找到值的平均值 [英] How to find the mean of the value at an index in numpy

查看:174
本文介绍了如何在numpy中的索引处找到值的平均值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个如下所示的numpy数组,并且我想计算每个数组的索引0(1,1,1)或索引3(4,5,6)的平均值。是否有一个numpy函数可以解决这个问题?我尝试了numpy.mean,但无法解决问题。

Suppose I have a numpy array as show below and I want to calculate the mean of values at index 0 of each array (1,1,1) or index 3 (4,5,6). Is there a numpy function that can solve this? I tried numpy.mean, but it does not solve the issue.

[[1,2,3,4],
[1,2,3,5],  --> = [(1+1+1)/3, (2+2+2)/3, (3+3+3)/3, (4+5+6)/3] --> [1,2,3,5] 
[1,2,3,6]]


推荐答案

沿第一个轴-轴0 取平均值:

Take the mean along the first axis - axis 0:

>>> a = np.array([[1,2,3,4],
...               [1,2,3,5],  
...               [1,2,3,6]])
>>> a.mean(axis=0)
array([ 1.,  2.,  3.,  5.])

这篇关于如何在numpy中的索引处找到值的平均值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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