Julia finding multiple argmin
Asked Answered
S

1

7

I have been trying to find the multiple argmin of the list, and on the explanation part it declares that "If there are multiple minimal elements, then the first one will be returned."

For example,

x=[1,-1,-1,2]
argmin(x)

It only returned 2. However, I would like to get 2,3. Is there any possible way to fix it?

Sharie answered 21/4, 2020 at 20:19 Comment(0)
M
6

No, you have to find that manually with findall:

findall(==(minimum(x)), x)

Note that this is efficient, it will not call minimum more than once. The expression ==(minimum(x)) defines a function.

Mindful answered 21/4, 2020 at 20:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.