Get mean of 2D slice of a 3D array in numpy
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have a numpy array with a shape of: ( 11L , 5L , 5L ) I want to calculate the mean over the 25 elements of each 'slice' of the array [0, :, :], [1, :, :] etc, returning 11 values. It seems silly, but I can't work out how to do this. I've thought the mean(axis=x) function would do this, but I've tried all possible combinations of axis and none of them give me the result I want. I can obviously do this using a for loop and slicing, but surely there is a better way? 回答1: Use a tuple for axis : >>> a = np . arange ( 11 * 5 * 5 ).