0

I used np.random.choice(datasize, n_train_data) to shuffle dataset and split. As to test dataset:

np.random.seed(99)

dataset_index = np.arange(datasize)
train_index_arr = np.random.choice(dataset_index, n_train_data)
mask = ~np.isin(dataset_index, train_index_arr))
val_index_arr = dataset_index[mask]

However it return wrong result. Please kindly refer to the code below:

idx = np.random.choice(range(1000), 300)
sum(~np.isin(np.arange(1000), idx))
>> 742 # expected result: 700

What am I doing wrong?

0

1 Answer 1

2

You need to set replace = False so that the choices you make don't go back into the choice pool

idx = np.random.choice(range(1000), 300, replace = False)
sum(~np.isin(np.arange(1000), idx))
Out[]: 700
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.