0

Array:

arr = np.ones([4,4])

array([[ 1.,  1.,  1.,  1.],
       [ 1.,  1.,  1.,  1.],
       [ 1.,  1.,  1.,  1.],
       [ 1.,  1.,  1.,  1.]])

I use shift from scipy.ndimage.interpolation as follows:

shift(arr,1, cval=np.nan)

array([[ nan,  nan,  nan,  nan],
       [ nan,   1.,   1.,   1.],
       [ nan,   1.,   1.,   1.],
       [ nan,   1.,   1.,   1.]])

HOWEVER, I want:

array([[ nan,  nan,  nan,  nan],
       [ 1.,   1.,   1.,   1.],
       [ 1.,   1.,   1.,   1.],
       [ 1.,   1.,   1.,   1.]])

Basically, I want to SHIFT all columns data down the rows and boot the last row out of my data set. Pandas has the shift function that can do this but I'm not certain how it can be done in Numpy.

1 Answer 1

2

You can change the shift parameter (second parameter) of the shift function from scipy.ndimage.interpolation as follows:

shift(arr, (1, 0), cval=np.nan)

Here, (1, 0) means a shift of 1 in the first dimension, and 0 in the second dimension.

Sign up to request clarification or add additional context in comments.

1 Comment

Might also want to explicitly set mode='constant'

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.