I have an issue with random.sample function. Here is the code:
import random
import numpy as np
simulateData = np.random.normal(30, 2, 10000)
meanValues = np.zeros(1000)
for i in range(1000):
dRange = range(0, len(simulateData))
randIndex = np.random.sample(dRange, 30)
randIndex.sort()
rand = [simulateData[j] for j in randIndex]
meanValues[i] = rand.mean()
This is the error:
TypeError Traceback (most recent call last)
<ipython-input-368-92c8d9b7ecb0> in <module>()
20
21 dRange = range(0, len(simulateData))
---> 22 randIndex = np.random.sample(dRange, 30)
23 randIndex.sort()
24 rand = [simulateData[i] for i in randIndex]
mtrand.pyx in mtrand.RandomState.random_sample (numpy\random\mtrand\mtrand.c:10022)()
TypeError: random_sample() takes at most 1 positional argument (2 given)
I found several past references where such an error was supposedly addressed via changing import order like in my case above (random, before numpy). Supposedly random module gets overwritten somehow during the import while I can not imagine why would that be in a high level language. However in my case it did not work. I tried all possible variations but came with no solution
The problem in itself is an attempt to bootstrap: get random samples (equal size) from the initial distribution and measure the mean and std.
I am puzzled, especially since the solution which is supposed to work does not. I have Python 2.7
Please, help