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!

J. Smith
  • 143
  • 1
  • 2
  • 11
  • Or `for plane in np.rollaxis(matrix, -1): print(plane)`. Or even just `print(np.rollaxis(matrix, -1))` – Eric Nov 30 '16 at 23:00
  • Possible duplicate of [numpy 3D-image array to 2D](http://stackoverflow.com/questions/14365029/numpy-3d-image-array-to-2d) – Simon Dec 01 '16 at 00:28

1 Answers1

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]]
evan.oman
  • 5,922
  • 22
  • 43