Consider a matrix where you don’t need the third column:
X = zeros(Int64, (8, 3));
X[:, 1] = [0, 0, 0, 0, 1, 1, 1, 1];
X[:, 2] = [1, 1, 2, 2, 1, 1, 2, 2];
julia> X
8×3 Matrix{Int64}:
0 1 0
0 1 0
0 2 0
0 2 0
1 1 0
1 1 0
1 2 0
1 2 0
So you want to select (copy) everything except column 3:
8×2 Matrix{Int64}:
0 1
0 1
0 2
0 2
1 1
1 1
1 2
1 2
Is there a shorthand way to express this?
These work, but feel impractical when you have a large number of columns:
X[:, [1, 2]]
X[:, sort(collect(setdiff(Set([1, 2, 3]), Set([3]))))]
>Solution :
There are plenty of ways to do this. Below is a solution in which you express which ranges of column numbers to include:
X = zeros(Int64, (8, 3));
X[:, 1] = [0, 0, 0, 0, 1, 1, 1, 1];
X[:, 2] = [1, 1, 2, 2, 1, 1, 2, 2];
return X[:,1:2] #Columns 1 through 2 are being directly included.
Alternatively, you could express which you would like to exclude, which is perhaps a more widely useful version of the code:
return X[:, 1:end .!= 3] #column number 3 is being directly excluded.
Both of which would return:
8×2 Matrix{Int64}:
0 1
0 1
0 2
0 2
1 1
1 1
1 2
1 2