Hi,
I’m trying to find where the elements of an Array{Int64,1} are indexed in another Array{Int64,1}. I’m trying something like the following (but b and a are much longer).
b = [7;3];
a = 1:10;
c = findall((in)(b), a);
c = [3;7]
Is there a way to have this sorted? i.e I want c to be [7;3].
It is sorted — in ascending order. Use reverse(c)
.
PS: also, please quote your code.
Hi, unfortunately that doesn’t work - i think i wasn’t clear in my example, here’s a better one. a
is not in ascending order, it is just an Array of random integers and b
has more than 2 elements. See the following example:
a = [3;11;18;7;27;5];
b = [3;5;7];
c = findall((in)(b),a);
c
3-element Array{Int64,1}:
1
4
6
reverse(c)
3-element Array{Int64,1}:
6
4
1
But i want it to return [1;6;4] of course.
You want a different operation entirely: indexin
.
julia> indexin(b, a)
3-element Array{Union{Nothing, Int64},1}:
1
6
4
3 Likes