yujuezhao
yujuezhao

Reputation: 1105

Get average of the numpy ndarray

I have a shape of A = (8, 64, 64, 64, 1) numpy.ndarray. We can use np.means or np.average to calculate the means of a numpy array. But I want to get the means of the 8 (64,64,64) arrays. That is, i only want 8 values, calculated from the means of the (64,64,64). Of course I can use a for loop, or use [np.means(A[i]) for i in range(A.shape[0])]. I am wondering if there is any numpy method to do this

Upvotes: 0

Views: 387

Answers (1)

SpghttCd
SpghttCd

Reputation: 10850

You can use np.means axis kwarg:

np.mean(A, (1, 2, 3, 4))

The same works with np.average, too.

Upvotes: 2

Related Questions