Using the find () function with two vectors

I use the Julia programming language, and I know that you can use the find function as follows:

a = [ 1 2 3 4 3 5 3 6 7 8 9 3 ]
find(a .== 3)

He will return: 3, 5, 7, 12

Simple enough.

However, my question is: what if we want to replace 3 in the above code as a vector.

For instance:

a = [1 2 3 4 5 6 7]
b = [1 9 5 8]

The following syntax did not work for me, but it conveys my idea. How can I do the following correctly:

find (a .== b)

If we want him to return 1, 3?

I know that the matching function in R does it well, but I have a very large dataset, and R does not handle it well.

+3
source share
2 answers

Another way is to use the findin / 2 function :

julia> findin(b,a)
2-element Array{Int64,1}:
 1
 3

julia> findin(a,b)
2-element Array{Int64,1}:
 1
 5
+7

:

julia>> find(x->x in b, a)
2-element Array{Int64,1}:
 1
 5

, 1, 3:

julia> find(x->x in a, b)
2-element Array{Int64,1}:
 1
 3

a = [1, 2, 3, 4, 5, 6, 7]
b = [1, 9, 5, 8]

, , Julia.

, find(x->x==3, a), find(a.==3), , , a .

: , find. ,

find(f, a)

f a , find.

+3

Source: https://habr.com/ru/post/1662201/


All Articles