Here is my code in Julia. I want to find locations of elements of array b in array a.
a = [2,4,1,3]
b = [1,4]
c=[]
for i in 1:length(b)
push!(c, findfirst(isequal(b[i]), a));
end
println(c)
The result is [3, 2]. It's correct. But I believe there should be a more Julian (efficient) approach. I tried
julia> findall(x -> x == b, a)
0-element Array{Int64,1}
It's wrong. Then
julia> findall(x -> x == .b, a)
ERROR: syntax: invalid identifier name "."
or
julia> findall(x -> x .== b, a)
ERROR: TypeError: non-boolean (BitArray{1}) used in boolean context
The following result is wrong!
julia> findall(x -> x in b, a)
2-element Array{Int64,1}:
2
3
I think it considered 'b' as a set and ignored the sequence of elements in 'b'. I want the correct sequence [3,2]. Can anyone help me? Thanks.