xirururu - 1 year ago 90

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]`

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

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]),)
```

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**