If your matrix, calling it a , is saved in CSR format, then a.data has all nonzero entries sorted by rows, and a.indptr has the index of the first element of each row. You can use this to calculate what you are doing as follows:
def sparse_max_row(csr_mat): ret = np.maximum.reduceat(csr_mat.data, csr_mat.indptr[:-1]) ret[np.diff(csr_mat.indptr) == 0] = 0 return ret
source share