[Numpy-discussion] Inplace shift

Keith Goodman kwgoodman@gmail....
Fri Jun 6 13:24:10 CDT 2008


I'd like to shift the columns of a 2d array one column to the right.
Is there a way to do that without making a copy?

This doesn't work:

>> import numpy as np
>> x = np.random.rand(2,3)
>> x[:,1:] = x[:,:-1]
>> x

array([[ 0.44789223,  0.44789223,  0.44789223],
       [ 0.80600897,  0.80600897,  0.80600897]])

What I'm trying to do (but without the copy):

x2 = x.copy()
x[:,1:] = x2[:,:-1]


More information about the Numpy-discussion mailing list