I have a 2D array m = np.array([[0,0,0,0], [0, 0.08, 0.1, 0.02], [0,0.12,0.15,0.03], [0,0.2,0.25,0.05]]) and a list of arrays of indices
filter_indices=[np.array([[1,1],[3,1],[1,3]]), np.array([[2,2],[2,3],[2,3]]), np.array([3,3]) ]
For each element of the list filter_indices, I want to sum the elements of m at the corresponding indices and store them in a 1D array. I can currently do it as a list comprehension:
get = lambda m, indices, idx: np.sum(m[tuple(indices[idx].T)])
as_list = [get(m, filter_indices, i) for i in range(0,3)]
as_vector = np.array(as_list)
which gives me the right answer array([0.3 , 0.21, 0.05])
but I would like to somehow vectorize it to avoid having to iterate over the list