I have a multidimensional ndarray and I'm looking to randomly select 1000 arrays WITH replacement. This seem to me to be simple, but the with replacement part I'm struggling to incorporate.
There are 3065 arrays in this ndarray.
np.shape(train_spam)
(3065L, 58L)
I tried to use np.random.shuffle() but this does not take into account the with replacement.
np.random.shuffle(train_spam)
X_train = train_spam[:1000,1:57]
My final output would have ea shape of (1000L, 58L).
I suppose I could run a loop with a ndarray with
X_train = train_spam[0:57]
and then append but I can't figure out how to append correctly, so it looks the same. Any help would be greatly appreciated
selection = [arrays[random.randrange(n)][:] for i in range(k)]wherenis the size ofarraysandkis the number of elements you want to select with replacement.choose(). Does this work for you?train_spam.choose([random.randrange(3065) for i in range(1000)])