Shifting numpy array contents

John Hunter jdhunter at ace.bsd.uchicago.edu
Thu Mar 6 14:13:49 EST 2003


>>>>> "Heiko" == Heiko  <h.stegmann at arcor.de> writes:

    Heiko> Is there a simple way to shift the contents of
    Heiko> multi-dimensional numpy arrays index-wise? E.g., shifting a
    Heiko> complete row by a given number of indices to the right,
    Heiko> using slicing or any simple concept rather than loop
    Heiko> constructs?

It would help if you were a little more concrete about what you want
to do.  For example, should the array change size after the shift?

Here is a shift of all the rows up one, overwriting the first row and
leaving the last row intact

  A = array([[1,2,3], [4,5,6], [7,8,9], [10,11,12]])
  A[:-1] = A[1:]

This shifts just the 4th row up

  A = array([[1,2,3], [4,5,6], [7,8,9], [10,11,12]])
  A[2] = A[3]

Is this the kind of thing you had in mind.  Details, please...

John Hunter 





More information about the Python-list mailing list