Re: [julia-users] Re: How can I find the common elements of two matrix(or arrays)?

2016-07-21 Thread Joshua Ballanco
Use `enumerate`: julia> a = [1,3,5,8] julia> b = [1,2,5,7] julia> intersect(enumerate(a), enumerate(b)) 2-element Array{Tuple{Int64,Int64},1}: (1,1) (3,5) On July 5, 2016 at 13:20:15, siyu song (siyuphs...@gmail.com) wrote: Good to know this method. Thanks a lot. 在 2016年7月6日星期三

Re: [julia-users] Re: How can I find the common elements of two matrix(or arrays)?

2016-07-05 Thread siyu song
Good to know this method. Thanks a lot. 在 2016年7月6日星期三 UTC+9上午1:45:21,Cedric St-Jean写道: > > In Julia, if speed isn't too important, this gives the same results: > > a, b = [-1,-2,-3], [-3,-4,-5,-2] > inter = intersect(a, b) > (Int[findfirst(a, x) for x in inter], Int[findfirst(b, x) for x in

Re: [julia-users] Re: How can I find the common elements of two matrix(or arrays)?

2016-07-05 Thread Cedric St-Jean
In Julia, if speed isn't too important, this gives the same results: a, b = [-1,-2,-3], [-3,-4,-5,-2] inter = intersect(a, b) (Int[findfirst(a, x) for x in inter], Int[findfirst(b, x) for x in inter]) And it should be a good deal faster than the MATLABism. Other functions you might find useful:

[julia-users] Re: How can I find the common elements of two matrix(or arrays)?

2016-07-05 Thread siyu song
Thanks, Fred, for your answer. But in fact I want to know the index of the common elements of two integer vectors(Elements are all different in each vectors). For example, v1 = [1,2,3] and v2[3,4,5,2]. So the answer should be common_index1 = [2,3], common_index2 = [1,4]. I use a function as

[julia-users] Re: How can I find the common elements of two matrix(or arrays)?

2016-07-05 Thread Fred
julia> a=[1,3,5,7] 4-element Array{Int64,1}: 1 3 5 7 julia> b=[2,3,5,6,7] 5-element Array{Int64,1}: 2 3 5 6 7 julia> intersect(a,b) 3-element Array{Int64,1}: 3 5 7 julia> union(a,b) 6-element Array{Int64,1}: 1 3 5 7 2 6 Le lundi 4 juillet 2016 04:18:10 UTC+2, siyu song a

[julia-users] Re: How can I find the common elements of two matrix(or arrays)?

2016-07-04 Thread siyu song
Oh you are right. ".==" works very well. I don't know this before. I am still a newcomer here. Thank you very much. 在 2016年7月4日星期一 UTC+9上午11:35:10,Cedric St-Jean写道: > > Maybe I'm missing something, but doesn't find(Mat_a .== Mat_b) work as in > Matlab? (Julia needs the dot before the ==) > > On

[julia-users] Re: How can I find the common elements of two matrix(or arrays)?

2016-07-03 Thread Cedric St-Jean
Maybe I'm missing something, but doesn't find(Mat_a .== Mat_b) work as in Matlab? (Julia needs the dot before the ==) On Sunday, July 3, 2016 at 10:18:10 PM UTC-4, siyu song wrote: > > But intersect doesn't tell us the index of the elements in the > matrix(array), I think. > 在 2016年7月4日星期一

[julia-users] Re: How can I find the common elements of two matrix(or arrays)?

2016-07-03 Thread Fred
intersect(a,b) union(a,b) Le dimanche 3 juillet 2016 19:54:02 UTC+2, siyu song a écrit : > > In MATLAB, it's easy to do this by using : find(Mat_a == Mat_b). Is there > an easy similar way to do this? >