I have a really big list. Imagine it looks something like this:
test = ['llama', 'cow', 'horse', 'fish', 'sheep', 'goat', 'cat', 'dog']
I want to sample out of this list many times. I want each sample to be taken without replacement. I want to avoid for loops in this case.
I've seen many solutions on StackOverflow that are close, but not exactly what I need here. Let's say each sample I wanted was to be of size 3. If I wanted to sample with replacement, this would work:
np.random.choice(test, size=(100, 3))
This would give me 100 rows with a sample of 3 in each row. The problem is that any particular row might have repeats, and I can't ask it to sample without replacement, because 300 > len(test)
.
Is there a way around this that maintains randomness? I saw potential solutions that use np.argsort, but I'm not sure that they're still actually random, considering sorting is being done.