2

When I print my 5x5x3 numpy array, it prints as 5 5x3 arrays.

I have read in a 5 pixel x 5 pixel rgb image and want to view the 5x5 arrays that are R, G and B. How do I do this?

Thanks!

2
  • Or for plane in np.rollaxis(matrix, -1): print(plane). Or even just print(np.rollaxis(matrix, -1)) Commented Nov 30, 2016 at 23:00
  • Possible duplicate of numpy 3D-image array to 2D Commented Dec 1, 2016 at 0:28

1 Answer 1

0

Something like this should work:

In [1]: import numpy as np

In [2]: a = np.array([[[1,2,3], [3,4,3]],[[5,6,3], [7,8,3]]])

In [3]: a.shape
Out[4]: (2, 2, 3)

In [4]: for i in range(a.shape[-1]):
    ...:     print(a[:,:,i])
    ...:
[[1 3]
 [5 7]]
[[2 4]
 [6 8]]
[[3 3]
 [3 3]]
Sign up to request clarification or add additional context in comments.

Comments

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.