[Numpy-discussion] Shift or rotate command?

Bill Baxter wbaxter at gmail.com
Sun Sep 24 21:04:15 CDT 2006


Hmm.  Yes maybe a shift w/fill would be useful too.  I can't recall
needing such a thing, but it could probably also be implemented easily
in a way similar to roll() above.  A multi-axis roll might also be
nice.  Could just allow roll's shiftby and axis args to be tuples.

Looking closer at the existing 'rollaxis',
   numpy.rollaxis(a, axis, start=0)
   if a.shape is (3,4,5,6)
   rollaxis(a, 3, 1).shape is (3,6,4,5)
   rollaxis(a, 2, 0).shape is (5,3,4,6)
   rollaxis(a, 1, 3).shape is (3,5,4,6)
   rollaxis(a, 1, 4).shape is (3,5,6,4)

it occurs to me that what it is actually doing is not what we've been
calling 'rolling'.  It's just a move, really (remove value from one
place and re-insert in another).  So perhaps the name should be
'moveaxis' instead?

--bb


On 9/25/06, Alan G Isaac <aisaac at american.edu> wrote:
> On Mon, 25 Sep 2006, Bill Baxter apparently wrote:
> > Went ahead and added an enhancement request:
> > http://projects.scipy.org/scipy/numpy/ticket/293
> > This is something I've wanted in the past too.
>
>
> GAUSS draws a useful distinction between "shifting" and
> "rotating":
>
> Works roughly like this for the 2D case:
>
> #rotater: rotate row elements
> # Format:    y = rotater(x,r)
> #            rotater(x,r)
> # Input:     x           RxK array
> #            rotateby    size R integer array, or integer (rotation amounts)
> # Output:    y           RxK array:
> #                          rows rotated by rotateby
>
> #shiftr: shift row elements and fill with fv
> # Format:    y = shiftr(x,shiftby,fv)
> # Input:     x        RxC array
> #            shiftby  Rx1 array or scalar (shift amounts)
> #            fv       Rx1 array or scalar (fill values)
> # Output:    y        RxC array:
> #                       rows shifted by shiftby
> #                       rows filled with fill
>
> fwiw,
> Alan Isaac




More information about the Numpy-discussion mailing list