saas
saas

Reputation: 15

return the entire row with has the max value in numpy - python

val = np.array([[1, 3], [2, 5], [0, 6], [1, 2] ])
print(np.max(val))
6

I also want to print the row [0,6]. with axis it returns all the value from other rows as well. argmax doesnt return the row index.

Upvotes: 0

Views: 74

Answers (1)

Scott Boston
Scott Boston

Reputation: 153460

One way is to use np.where which return indexes where true:

r,_ = np.where(val == np.max(val))
val[r]

Output:

array([[0, 6]])

Upvotes: 1

Related Questions