Shift all indices in NumPy array Shift all indices in NumPy array numpy numpy

Shift all indices in NumPy array


You can use

y = numpy.roll(x, 1)y[0] = 0

or

y = numpy.r_[0, x[:-1]]


If you wanted to do this in-place, you could also do:

x[1:] = x[:-1]x[0] = 0