0

I have this array in python:

     ([[0., 0., 1.],
       [0., 0., 1.],
       [0., 0., 1.],
       [0., 0., 1.],
       [0., 1., 0.],
       [0., 1., 0.],
       [1., 0., 0.],
       [1., 0., 0.],
       [1., 0., 0.],
       [1., 0., 0.]])

How to go about converting this 10 x 3 array to a 10 x 1 array with the single array being equal to the column number where there is a 1 in the row. This output in this example case should be:

([2,2,2,2,1,1,0,0,0,0], dtype=int64)

Any help will be greatly appreciated as to how to do this in python. Thank you!

Joe
  • 357
  • 2
  • 10
  • 32
  • 1
    `your_array.argmax(1)` check https://stackoverflow.com/questions/36300334/understanding-argmax – Onyambu Jun 23 '22 at 05:37

1 Answers1

1
arr = [[0,0,1],[0,1,0]]
flattened = [x.index(1) for x in arr]
Hunter G
  • 29
  • 4