[英]How to get the mean of a 3D array over 2D?
I have an array with the following shape (7352, 128, 6)我有一个具有以下形状的数组 (7352, 128, 6)
How can I get the "mean" of the 1st and 2nd dimensions with NumPy in Python?如何在 Python 中使用 NumPy 获得第一维和第二维的“平均值”?
The resulting shape of the "means" I want to obtain is (1, 6).我想要获得的“手段”的结果形状是 (1, 6)。
You can do:你可以做:
np.mean(x, axis=(0, 1))
You resulting shape would be (6,) though.你得到的形状将是 (6,)。
numpy.mean()
with axis argument is proper solution. numpy.mean()
与轴参数是正确的解决方案。
import numpy as np
x = np.random.rand(7352, 128, 6)
x_mean = np.mean(x, axis=(0, 1))
print(x_mean.shape) # -> (6,)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.