计算numpy数组意味着跨轴

时间:2016-06-15 00:36:54

标签: python numpy

我有一个形状为numpy的数组:

(16L, 360L, 720L)

如何找到均值,以便生成的数组具有(16)形状,即我想要16个轴元素中每个元素的所有360 * 720值的平均值。

我试过了:

np.mean(arr, axis=0)

但是它的形状为(360 * 720)

1 个答案:

答案 0 :(得分:2)

什么是

np.mean(arr, axis=(1,2)

产生

来自mean文档

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

        .. versionadded: 1.7.0

        If this is a tuple of ints, a mean is performed over multiple axes,
        instead of a single axis or all the axes as before.