b.argsort(1)[:, :M]
b[np.arange(b.shape[0])[:, (None)], b.argsort(1)[:, :M]]
b[np.arange(b.shape[0])[:, (None)], b.argsort(1)[:, :M]].sum(1)
how to split numpy array and perform certain actions on split arrays [Python]