Mean Value For Dimension In Numpy Array
My numpy array (name: data) has following size: (10L,3L,256L,256L). It has 10 images with each 3 color channels (RGB) and each an image size of 256x256 pixel. I want to compute the
Solution 1:
If I understand your question correctly you want an array containing the mean value of each channel for each of the three images. (i.e. an array of shape (10,3)
) (Let me know in the comments if this is incorrect and I can edit this answer)
If you are using a version of numpy greater than 1.7 you can pass multiple axes to np.mean
as a tuple
mean_values = data.mean(axis=(2,3))
Otherwise you will have to flatten the array first to get it into the correct shape.
mean_values = data.reshape((data.shape[0], data.shape[1], data.shape[2]*data.shape[3])).mean(axis=2)
Post a Comment for "Mean Value For Dimension In Numpy Array"