average numpy array but retain shape
问题 I have a Numpy 3 axis array whose elements are 3 dimensional. I'd like to average them and return the same shape of the array. The normal average function removes the 3 dimensions and replace it with the average (as expected): a = np.array([[[0.1, 0.2, 0.3], [0.2, 0.3, 0.4]], [[0.4, 0.4, 0.4], [0.7, 0.6, 0.8]]], np.float32) b = np.average(a, axis=2) # b = [[0.2, 0.3], # [0.4, 0.7]] Result required : # b = [[[0.2, 0.2, 0.2], [0.3, 0.3, 0.3]], # [[0.4, 0.4, 0.4], [0.7, 0.7, 0.7]]] Can you do