-2
a = np.array([[0, 0, 1], [1, 2, 3], [3, 4, 5]]) #a.shape = (3,3)

How to replace each array in a with its max value?

Excepted output - a = np.array([1, 2, 5]) #a.shape = (3,1)

Thanks

Almog-at-Nailo
  • 1,152
  • 1
  • 4
  • 20
vishak raj
  • 21
  • 4
  • What do you exactly mean by *max value*? I think you need to clarify how that output is expected. – Mustafa Aydın Jul 07 '21 at 07:30
  • 2
    If there is a typo and you expect `[1, 3, 5]` instead, that's the exact same question you asked [here](https://stackoverflow.com/questions/68270289/replacing-numpy-array-with-max-value)... – Mustafa Aydın Jul 07 '21 at 07:33
  • 1
    Does this answer your question? [Replacing numpy array with max value](https://stackoverflow.com/questions/68270289/replacing-numpy-array-with-max-value) – RandomGuy Jul 07 '21 at 07:40
  • @RandomGuy, thanks for writing, I found the answer, and also the link helps – vishak raj Jul 07 '21 at 13:41

1 Answers1

0

You can use:

a = np.amax(a, axis=1)

see the documentation here

Almog-at-Nailo
  • 1,152
  • 1
  • 4
  • 20