I am transitioning to Julia 1.0.2 and I realized that the find function is not defined. In a previous version (Julia 0.6) I could write
find(x -> x<0, my_var)
In order to get the negative elements of the array called my_var. When I run the same code in Julia 1.0.2 I get the following error:
UndefVarError: find not defined
I couldn't find whether the find function is implemented under a different name or if it has been dropped. Is there any Julia 1.0.2 function that would be equivalent to the find function in previous Julia versions?
Use filter()
:
julia> filter(x -> x<0, -5:5)
5-element Array{Int64,1}:
-5
-4
-3
-2
-1
Another option is to use findall()
to get the indices of elements:
julia> indices = findall(x -> x<0, -5:5)
5-element Array{Int64,1}:
1
2
3
4
5
You can use getindex()
to get the actual values, e.g.:
julia> getindex(-5:5,indices)
5-element Array{Int64,1}:
-5
-4
-3
-2
-1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With