[Numpy-discussion] Inplace shift
Keith Goodman
kwgoodman at gmail.com
Fri Jun 6 14:24:10 EDT 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