xirururu - 1 year ago 52

Python Question

I have an array and I want to find the indices of the maximum values.

For example:

`myarray = np.array([1,8,8,3,2])`

I want to get the result:

`[1,2]`

(Actually I tried

`np.argmax(myarray)`

`[1]`

Answer Source

Given:

```
>>> myarray = np.array([1,8,8,3,2])
```

You can do:

```
>>> np.where(myarray==myarray[np.argmax(myarray)])
(array([1, 2]),)
```

or,

```
>>> np.where(myarray==max(myarray))
(array([1, 2]),)
```

or,

```
>>> np.nonzero(myarray==max(myarray))
(array([1, 2]),)
```