I have a folder with 100 repetition files. Each file is an array with 300 values. I use the glob function to combine these all into a single array of arrays.
I would like to create a new array of arrays (i.e., a subset of the original) with the criterion being only the lists where the last value in each list is greater than 1.
I think np.where is the best way to achieve this but I am not sure how to apply it when iterating through an array of arrays. So far I have:
reps=sorted(glob.glob('C:/Users/Repetitions/*') outbreaks= for r in reps: prevalence=np.loadtxt(r,delimiter=',') if np.where(prevalence[-1] > 1): outbreaks.append(prevalence)
This doesn’t work as I expected it wouldn’t -all of the arrays get added to the new outbreaks list. How do I change the second to last line to achieve what I am looking for?
You will not need
np.where if I understand the question correctly. You can use:
for r in reps: prevalence=np.loadtxt(r,delimiter=',') if prevalence[-1] > 1: outbreaks.append(prevalence)
However, this creates a list of array and if you need array of arrays simply do:
outbreaks = np.array(outbreaks)
But I don’t see a point in having an array of arrays. You probably are better off with your original list of arrays.