How to sum every element in a numpy array divisible by 5 using vectorization?

Viewed 1410

I am looking for a vectorization method for summing all elements of a numpy array that is evenly divisible by 5.

For example, if I have

test = np.array([1,5,12,15,20,22])

I want to return 40. I know about the np.sum method, but is there a way to do this using vectorization given the X%5 == 0 conditional?

1 Answers
Related