Depending on the size of the array there are several solutions, the simplest is to access the array f as f[a*x+b]
and checking if that is a valid index. Here is a code that creates the shifted array:
import numpy as np
def scale_shift(f, a , b):
i = np.arange(len(f))*a+b
y = f[i[(0<=i) & (i<len(f))]]
return y
n = 10
f = np.random.rand(n)
print(scale_shift(f,2,1))
Note that the length of the new array will depend on the shift. You can use %
if you want to wrap around the boundaries
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…