The pixels variable has shape 32x32x3, it is a numpy array. You can easily manipulate with numpy arrays without pure-Python loops; If you want to invert all rows of the image, just do:
inverted = pixels[:, ::-1, :]If you want to invert all odd rows, do
inverted = pixels.copy() inverted[::2,...] = inverted[::2, ::-1, :] # now inverted var. has desired form