[Numpy-discussion] Offset 2D arrays

Eric Nodwell nodwell at physics.ubc.ca
Mon Sep 17 16:35:03 CDT 2001


Mike,

As was pointed out to me when I had a similar query, one way to do
this is to define a class which inherits UserArray and refine indexing
and slicing.  I actually shifted by an offset of one in the opposite
direction to what you seem to require.  I had intended to generalize
to arbitrary offsets, but haven't had the time yet.  Anyway, you're
welcome to grab my code at
http://www.physics.ubc.ca/~mbelab/python/arrayone as a starting point
for your class.  There are still some issues and quirkiness with the
code, but they're documented along with work-arounds, and suggestions
for fixes have been made on this mailing list.  Again, it's a matter
of time...

regards,
Eric


On Mon, Sep 17, 2001 at 05:20:06PM -0600, Mike Romberg wrote:
> 
>   I am attempting to create 2D arrays which are offset copies of a
> given starting array.  For example if I have a 2D array like this:
> 
> array([[1, 2, 3],
>        [4, 5, 6],
>        [7, 8, 9]])
> 
>   I would like to offset it by some amount in either or both the x and
> y dimension.  Lets say that both the  x and y offset would be 1.  Then
> I would like to have an array like this:
> 
> 
> 
> array([[5, 6, 0],
>        [8, 9, 0],
>        [0, 0, 0]])
> 
>   Here I don't really care about the values which are now zero.  The
> main point is that now I can compare the data values at any given
> (x,y) point with the values at the adjacent point (over one on each
> axis).  This would be useful for the kinds of calculations we need to
> do.  I just can't come up with a numeric way to do this.  Does anyone
> have any ideas?
> 
> Thanks alot,
> 
> Mike Romberg (romberg at fsl.noaa.gov)
> 
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion

-- 
********************************
Eric Nodwell
Ph.D. candidate
Department of Physics
University of British Columbia

tel: 604-822-5425
fax: 604-822-5324 
nodwell at physics.ubc.ca




More information about the Numpy-discussion mailing list