0

I have a numpy array of shape (66,67,4). When I do np.mean(imarray) it calculates the array mean but takes all channels into consideration. I want to calculate the mean of only channel 1 and channel 3, separately.

I am doing this since I have a .tif file and it contains certain attributes in each band and they are essentially independent from each other so I need to calculate means separately

3
  • numpy.org/doc/stable/reference/arrays.indexing.html Commented Sep 4, 2022 at 13:04
  • np.mean(im[...,1]) and np.mean(im[...,3]) Commented Sep 4, 2022 at 13:08
  • Please provide enough code so others can better understand or reproduce the problem. Commented Sep 4, 2022 at 16:11

1 Answer 1

1

The mean of channel 1 - assuming you meant the first channel:

np.mean(array[:, :, 0])
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much for this. And channel 3 would be np.mean(array[:,:,2])?
@AhmedTech Yes, again I'm assuming you're aware of zero-based indexing

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.