def rle_encode(img):
pixels = img.T.flatten()
pixels[0] = 0
pixels[-1] = 0
runs = np.where(pixels[1:] != pixels[:-1])[0] + 2
# print(runs.shape) should be even, but i got an odd sometimes
# if runs.shape[0]%2!=0:
# runs = runs[:-1]
runs[1::2] -= runs[::2]
return ' '.join(str(x) for x in runs)
runs[1::2] -= runs[::2]
无法广播