如何获得与numpy的平均阵列 [英] How to get a mean array with numpy

查看:181
本文介绍了如何获得与numpy的平均阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2,4-D(D0,D1,D2,D3,D4)numpy的阵列。我希望得到一个2-D(D0,D1)的意思是数组,现在我的解决方法是如下:

I have a 4-D(d0,d1,d2,d3,d4) numpy array. I want to get a 2-D(d0,d1)mean array, Now my solution is as following:

area=d3*d4
mean = numpy.sum(numpy.sum(data, axis=3), axis=2) / area

但如何使用 numpy.mean 来获得平均阵列。

推荐答案

您可以重塑,然后执行平均:

You can reshape and then perform the average:

res = data.reshape(data.shape[0], data.shape[1], -1).mean(axis=2)

在numpy的1.7.1可以传递一个元组到参数:

In NumPy 1.7.1 you can pass a tuple to the axis argument:

res = np.mean(data, axis=(2,3,4))

这篇关于如何获得与numpy的平均阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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