Julia 找到多个 argmin

Julia finding multiple argmin

我一直试图找到列表的多个 argmin,在解释部分它声明 "If there are multiple minimal elements, then the first one will be returned."

例如,

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

只返回了2。但是,我想得到 2,3。 有什么办法可以解决吗?

不,您必须使用 findall:

手动找到它
findall(==(minimum(x)), x)

请注意,这是高效的,它不会多次调用 minimum。表达式 ==(minimum(x)) 定义了一个函数。