0

I am triyng to get the 3 columns of a NumPy (RGB) array:

print px
[[[  0   0   0]
  [255 255 255]
  [255   0   0]
  [  0 255   0]
  [  0   0 255]]]

print px[:,0]
print px[:,1]
print px[:,2]

[[0 0 0]]
[[255 255 255]]
[[255   0   0]]

but I would like to get the R, G and B like

[[0 255 255 0 0]]
[[0 255 0 255 0]]
[[0 255 0 0 255]]

Could you help me?

Thank you

Hugo

1 Answer 1

3

Your array px is three-dimensional: the first dimension has just a single element: the complete arrays containing rows and colums. The second dimension is rows, the third is colums. Therefore, to select a column, and have it embedded in the outermost dimension like you have, use the following:

>>> print px[:,:,0]
[[  0 255 255   0   0]]

>>> print px[:,:,1]
[[  0 255   0 255   0]]

>>> print px[:,:,2]
[[  0 255   0   0 255]]
Sign up to request clarification or add additional context in comments.

1 Comment

I would like to transform this array into a Pandas Dataframe to use a scatter matrix. Should I use? f = pd.DataFrame(px[:,:,:], columns=['R', 'G', 'B'])

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.