Hi,
I just started learning Julia and I try to solve some basic ML tasks. It is quite common to generate a vector of indices for the training data and I would like to generate the complement.
For example I have a Vector of labels with a length of 10. I pick some indices.
selected = [1,3,5,8,9]
not_selected = Int[]
for i in 1:length(labels)
if i β selected
push!(not_selected, i)
end
end
I would like to write something like not_selected = 1:length(labels) .β selected
, but that complains because the dimensions do not match. So I write not_selected = 1:length(labels) .β Ref(selected)
, (which I do not understand btw) and it is almost what I want, but it returns a BitVector of the comparison results. Now I should create an other vector from the BitVector so I give up.
There must be a more elegant way, is not?
Now I can do this (features is a Matrix)
features_train = features[selected, :]
labels_train = labels[selected]
features_test = features[not_selected, :]
labels_test = labels[not_selected]
If the dataset is huge copying those Matrices/Vectors could be a problem, so I tried to remove rows from the initial data, but that does not look nice either:
function removeRows(A::Array, ints)
rows, cols = size(A)
out = similar(A, rows - length(ints), cols)
i = 1
for r in 1:rows
if !(r in ints)
@inbounds out[i, :] = A[r, :]
i += 1
end
end
return out
end
There is deleteat!
, but only for Vectors Oh, come on!
I probably do not find the proper functions, methods yet, but it is frustrating.
One more thing: I see DataFrames quite often, but I can not figure out what it can offer beyond the Base Array/Vector types besides named columns. Am I missing something there too?
Thanks,