positive = x > 0
positive0 = positive[:, 0:-3]
positive1 = positive[:, 1:-2]
positive2 = positive[:, 2:-1]
positive3 = positive[:, 3:]
has_pos_1_to_left1 = positive0
has_pos_1_or_2_to_right1 = positive2 | positive3
flanked_by_positives1 = has_pos_1_to_left1 & has_pos_1_or_2_to_right1
zeros = x == 0
zeros1 = zeros[:, 1:-2]
x1 = x[:, 1:-2]
x1[zeros1 & flanked_by_positives1] = 50
x[:, (-2)][zeros[:, (-2)] & positive[:, (-1)] & (positive[:, (-4)] or
    positive[:, (-3)])] = 50
Efficiently finding range of indices for positive values in 2D numpy array