Categories
Mastering Development

Combining/Summing rows of a numy array based on a list of indices

I have an array where I would like to add specific rows together in order to get an array with less rows. import numpy as np a = np.arange(50).reshape(5,10) b = [0,0,0,1,1,2,2,2,2,3] a array([[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19], […]