我正在转换到Julia 1.0.2,我意识到找不到find函数.在之前的版本(Julia 0.6)中我可以写
find(x -> x<0, my_var)
Run Code Online (Sandbox Code Playgroud)
为了获得名为my_var的数组的负面元素.当我在Julia 1.0.2中运行相同的代码时,我收到以下错误:
UndefVarError: find not defined
Run Code Online (Sandbox Code Playgroud)
我找不到find函数是以不同的名称实现还是已被删除.是否有任何Julia 1.0.2函数与以前的Julia版本中的find函数等效?
用途filter():
julia> filter(x -> x<0, -5:5)
5-element Array{Int64,1}:
-5
-4
-3
-2
-1
Run Code Online (Sandbox Code Playgroud)
另一种选择是使用findall()获取元素的索引:
julia> indices = findall(x -> x<0, -5:5)
5-element Array{Int64,1}:
1
2
3
4
5
Run Code Online (Sandbox Code Playgroud)
您可以使用getindex()获取实际值,例如:
julia> getindex(-5:5,indices)
5-element Array{Int64,1}:
-5
-4
-3
-2
-1
Run Code Online (Sandbox Code Playgroud)