I need a way to sample without replacement a certain array a. I tried two approaches (see MCVE below), using random.sample() and np.random.choice.
I assumed the numpy function would be faster, but it turns out it is not. In my tests random.sample is ~15% faster than np.random.choice.
Is this correct, or am I doing something wrong in my example below? If this is correct, why?
import numpy as np
import random
import time
from contextlib import contextmanager …Run Code Online (Sandbox Code Playgroud)