import numpy as np

def ones_row(row):
    if np.sum(row) >= 2:
        inds = np.where(row == 1)[0]
row[inds[0]:inds[-1]] = 1
return row
fast way to put ones beetween ones in each row of a numpy 2d array