Using BitArray to index into another Array

Hello, I am confused by the error I receive on a simple piece of code involving a BitArray. Here is a MWE:

a = [1 2 3];
B = [1 2 3; 4 5 6; 7 8 9];
ids = all(a. == B, dims=2);

Everything works as intended up to here and I obtain a BitArray that behaves as expected:

julia> all(a.==B,dims=2)
3×1 BitArray{2}:
 1
 0
 0

The problem is trying to use this BitArray to index any given array:

C = B[ids,:];

will throw an out of bounds error even though ids and B have the same maximum dimension. What am I doing wrong?

1 Like

ids is a matrix, not a vector. Maybe you are looking for something like

C = B[vec(ids), :]
2 Likes

Thank you, this was easier than I thought!