Find array elements not present in another array

This is one way to do it:

julia> y = unique(rand(1:10,10));

julia> y = unique(rand(1:10,10));

juila> z = x[(!in).(x,Ref(y))]
4-element Array{Int64,1}:
 7
 1
 6
 8


Of course (!in) is “not in”, the . broadcast that over x elements, and the Ref(y) guarantees that y will be not broadcasted.

This is the same, but prettier :slight_smile:

julia> z = x[x .∉ Ref(y)]
4-element Array{Int64,1}:
 7
 1
 6
 8

∉ is \notin + Tab.

4 Likes