I am facing the following issue. I have 4 data files (Data_1...Data_4) and I am trying to get a count of the number of items in column 2 which are less than or equal to 5. My following code does that job.
import numpy as np
filelist=[]
for i in list(range(1,5)):
filelist.append("/Users/Hrihaan/Desktop/Data_%s.txt" %i)
for fname in filelist:
data=np.loadtxt(fname)
z=data[:,1]
count= len([i for i in z if i <= -5]) # output 5 3 0 9
x= np.array(count)
Average=np.mean(x)
print(Average)
But I am stuck on how to deal with the output (5,3,0,9), I want to create an array from the output (count) to do simple mathematical calculations such as finding mean or median.So the mean should be (5+3+0+9/4 = 4.25) but when I tried the print(average), I am getting the same output 5 3 0 9, not the mean.
Any help would be greatly appreciated.
countin a list in yourfor frnameloop then turn that into an array outside/after the loop (remove the indentation)