-1

I have an array,

a = np.array([[0,9,8],[5,6,4]])

how to replace the each array in axis 1 with the max value of its array?

excepting output- a = np.array([9,6]) where 9 is the max value in [0,9,8] and 6 is the max value in [5,6,4]

thanks

vishak raj
  • 21
  • 4

2 Answers2

2

You should use

np.max(a, axis=1)

Link to documentation

Dirog
  • 48
  • 1
  • 8
0

another implementation you can do this

np.array([max(i) for i in a])
noob
  • 672
  • 10
  • 28