I have an array of size 10000, which contains random integers in it between 1-200 made using the following code:
x = np.random.randint(1,201, size=10000)
Next, I'm taking a random sample of 100, from this array and finding its mean value and putting it in an array called meen:
meen = []
for z in range(0, 50000):
randomSample=random.sample(list(x), 100 )
meanOfSample=np.mean(randomSample)
meen.append(meanOfSample)
I assume the past two codes work correctly because when I print(meen) I get an array:
[102.89, 106.14, 104.73, 97.78, 101.94, 98.94, 97.43, 98.92, 101.84, 99.64......]
fifty thousand long.
Now, the issue is when I am trying to find the number of values that fall within a range. For example, If I say I want to find the amount of numbers in meen that fall between 95 and 100 I tried the code:
((95 <= meen) & (meen <= 100)).sum()
But I get the error: "TypeError: '<=' not supported between instances of 'int' and 'list'"
I've seen various similar problems with this error on this website, but they all involved having bad arrays. I think my array is fine..? It only has numbers, no strings, or anything else that should cause issues.
meen
is a list, not a numpy array. Try adding this after your loop:
meen = np.asarray(meen)