I’m trying to calculate the total number of values above 1.6 in my list of 10,000 numbers. I’ve tried a few ways:
JavaScript
x
4
1
for value in chi_sq_values:
2
if value > 1.6:
3
print(len(value))
4
gives me the error in my title but the following works
JavaScript
1
4
1
greater = [i for i in chi_sq_values if i > 1.6]
2
total = len(greater)
3
print(total)
4
I want to try two methods to see validate my answer, how can i fix the first one so it works?
Advertisement
Answer
In the first code snippet, you try printing the len
of value
. As numpy.float64
has no len, you get an error.
Therefore, in order to count all values bigger then 1.6, you can simply use a counter:
JavaScript
1
6
1
counter = 0
2
for value in chi_sq_values:
3
if value > 1.6:
4
counter += 1
5
print(counter)
6