最低在朱莉娅的位置 [英] Location of minimum in Julia

查看:91
本文介绍了最低在朱莉娅的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Julia是否有内置命令来查找向量最小值的索引?例如,R具有which.min命令(当然还有which.max).

Does Julia have a build in command to find the index of the minimum of a vector? R, for example, has a which.min command (and a which.max, of course).

很明显,我可以自己写以下内容,但不必这么做会很高兴.

Obviously, I could write the following myself, but it would be nice not to have to.

function whichmin( x::Vector )
  i = 1
  min_x=minimum(x)
  while( x[i] > min_x ) 
    i+=1 
  end
  return i
end

很抱歉,是否曾经有人问过这个问题,但我找不到.谢谢!

Apologies if this has been asked before, but I couldn't find it. Thanks!

推荐答案

自0.7-alpha起,不推荐使用indminindmax. 使用 argmin

Since 0.7-alpha, indmin and indmax are deprecated. Use argmin and argmax instead.

对于矢量,它只返回线性索引

For a vector it just returns the linear index

julia> x = rand(1:9, 4)
4-element Array{Int64,1}:
 9
 5
 8
 5

julia> argmin(x)
2

julia> argmax(x)
1

如果同时查找索引和值,请使用 findmin findmax .

If looking for both the index and the value, use findmin and findmax.

对于多维数组,所有这些函数都返回CartesianIndex.

For multidimensional array, all these functions return the CartesianIndex.

这篇关于最低在朱莉娅的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆