When I used python to do the arnold scrambling algorithm, I found that the running time of the for loop was not good enough, and the time reached more than 1 second. I wanted to use numpy to speed up, but I don't know how to start. The arnold algorithm mainly uses the pixel coordinates of the original image to do a mapping transformation to obtain new coordinates, and fills the pixel values into the new coordinates.
def arnold(img):
r, c = img.shape
pic = np.zeros((r, c), np.uint8)
for i in range(r):
for j in range(c):
x = (i + j) % r
y = (i + 2 * j) % c
pic[x, y] = img[i, j]
return pic