It doesn't behave the same with respect to duplicates in A but I would do

N = 100
A = rand(N)
n = iceil(0.7 * N)
testindex = sample(1:size(A,1), replace=false, n)
testA = A[testindex]
trainindex = setdiff(1:N, testindex)
trainA = A[trainindex]

Den torsdag 26 mars 2015 kl. 06:21:42 UTC+1 skrev verylu...@gmail.com:
>
> Hi,
> I have an array of 100 elements. I want to split the array to 70 (test 
> set) and 30 (train set) randomly.
>
> N=100
> A = rand(N);
> n = convert(Int, ceil(N*0.7))
> testindex = sample(1:size(A,1), replace=false,n)
> testA = A[testindex];
>
> How can I get the train set?
>
> I could loop through testA and A to get trainA as below
>
> trainA = Array(eltype(testA), N-n);
> k=1
> for elem in A
>     if !(elem in testA)
>         trainA[k] = elem
>         k=k+1
>     end
> end
>
> Is there a more efficient or elegant way to do this?
>
> Thanks!
>

Reply via email to