# Issue with comparing two vectors with different sizes

I am wondering how I can get results for

``````R = [2, 2]
D = [1, 3]
J = [1, 1]
P = [1 3; 2 3; 6 3; 1 4; 2 4; 6 4; 1 5; 2 5; 6 5; 1 6; 2 6]
P[:,2] .== collect(R+1:R+D)
``````

similar to

``````R = [2, 2]
D = [1, 3]
J = [1, 1]
P = [1 3; 2 3; 4 3; 1 4; 2 4]
P[:,2] .== collect(R+1:R+D)
``````

that I got

``````5-element BitVector:
1
1
1
0
0
``````

What result do you expect for the first piece of code with `P`?

You can for eg. do:

``````julia> P[:,2] .== permutedims(R+1:R+D)
11×3 BitMatrix:
1  0  0
1  0  0
1  0  0
0  1  0
0  1  0
0  1  0
0  0  1
0  0  1
0  0  1
0  0  0
0  0  0

julia> sum(P[:,2] .== permutedims(R+1:R+D), dims = 2)
11×1 Matrix{Int64}:
1
1
1
1
1
1
1
1
1
0
0
``````

thanks for your response, it solved this issue but since I then want to use

``````findall(sum(P[:,2] .== permutedims(R+1:R+D), dims = 2)
.& (P[:,1] .== collect(R1]+D+1:R+D+J)))
``````

that produce

``````TypeError: non-boolean (Int64) used in boolean context
``````

while the previous version

``````findall((P[:,2] .== collect(R+1:R+D))
.& (P[i][:,1] .== collect(R+D+1:R+D+J)))
``````

was OK.

Use `vec(any(...))` instead of the `sum`:

``````julia> vec(any(P[:,2] .== permutedims(R+1:R+D), dims = 2))
11-element BitVector:
1
1
1
1
1
1
1
1
1
0
0

julia> findall(vec(any(P[:,2] .== permutedims(R+1:R+D), dims = 2)))
9-element Vector{Int64}:
1
2
3
4
5
6
7
8
9
``````

All of that allocates a lot though, unnecessarily. Now that I understand what you’re looking for, here’s a simpler and faster way to do this:

``````julia> P2[:, 2] .∈ Ref(R+1:R+D)
11-element BitVector:
1
1
1
1
1
1
1
1
1
0
0
``````

`findall` should work with this too.

Thanks a lot. I’m trying to produce following matrices

``````for i in 1:2
[1:size(P[i],1) P[i][[
findall(P[i][:,2] .== collect(R[i]+D[i]+1:R[i]+D[i]+J[i]));
findall((P[i][:,2] .== permutedims(R[i]+1:R[i]+D[i]))
.& (P[i][:,1] .== collect(R[i]+D[i]+1:R][i]+D[i]+J[i])));
findall((P[i][:,2] .== collect(R[i]+1:R[i]+D[i]))
.!= (P[i][:,1] .== collect(R[i]+D[i]+1:R[i]+D[i]+J[i])))], :]]
end
``````

but, I can get response for `P`, but got the mentioned error for `P`!

Can you explain what you’re trying to do? There’s probably a simpler and more readable and maintainable way to write this.

I’m trying to model a water network for max flow problem using a type of adjacent matrices. first column become number of pipes and second and third columns become “from” and “to” nodes. What makes the problem problematic is three type of nodes that must be distinguished and considered during the formulation and also coding.

I got this for first network

``````5×3 Matrix{Int64}:
1  1  4
2  2  4
3  4  3
4  1  3
5  2  3
``````

and trying to get similar for the second one as

``````11×3 Matrix{Int64}:
1  1  6
2  2  6
3  1  3
4  2  3
5  6  3
6  1  4
7  2  4
8  6  4
9  1  5
10  2  5
11  6  5
``````

What is important is the order of number of nodes in the second and third columns