Numpy - summing ndarray values based on conditional indexing

28 Views Asked by At

first question here. This is not easy to explain, so I'll give an example. I am pretty new to Numpy. I have a 2 dimentional array of 2048 columns x 100 lines (raw image, read by CV2) I would like to sum / create a new array contains only the values of the indexes of x8 separately.

example:

sum[0] = matrix[0][0] + matrix[0][8] + matrix[0][16] + ... + matrix[2040][100]
sum[1] = matrix[0][1] + matrix[0][9] + matrix[0][17] + ... + matrix[2041][100]
sum[2] = matrix[0][2] + matrix[0][10] + matrix[0][18] + ... + matrix[2042][100]
         .
         .
sum[7] = matrix[0][7] + matrix[0][15] + matrix[0][23] + ... + matrix[2047][100]

I do believe there is a nice way for doing it on arrays using Numpy without for loops. Does anyone knows how can I do it?

Thanks!

0

There are 0 best solutions below