I have some very long code, which I know can done more efficiently using a for loop. For context, the "matrix" is my dataset and I need to extract all the values where the second column is equal to 1,2,3...20, and sum the last four columns of those (resulting in a 20x4 matrice with the summed values)
But I need to write it using a loop, I would guess a for-loop.
I've tried the following:
M=np.zeros([20,10]) #creating empty matrix to fill in
for i in range(1,21):
M=matrix[matrix[:,1]==i]
sub=sum(M[:,6:10])
But the result is only the last run of the loop, that is the values where stackD[stackD[:,1]==20]. How can I do this with a for-loop? Thanks in advance.
1 ... to Nfor arbitrary positive nonzero integer N? Or is N potentially a value larger than 12?