[Numpy-discussion] Offset 2D arrays

Chris Barker chrishbarker at home.net
Mon Sep 17 16:41:02 CDT 2001


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:

> have any ideas?

This is not quite as clean as i would like, but this will work:

>>> a = array([[1, 2, 3],
...        [4, 5, 6],
...        [7, 8, 9]])
>>> m,n = a.shape
>>> b[:m-1,:n-1] =  a[1:,1:]
>>> b
array([[5, 6, 0],
       [8, 9, 0],
       [0, 0, 0]])
>>>

if b does not have to be the same shape as a, then it is really easy:

>>> b =  a[1:,1:]

-Chris


-- 
Christopher Barker,
Ph.D.                                                           
ChrisHBarker at home.net                 ---           ---           ---
http://members.home.net/barkerlohmann ---@@       -----@@       -----@@
                                   ------@@@     ------@@@     ------@@@
Oil Spill Modeling                ------   @    ------   @   ------   @
Water Resources Engineering       -------      ---------     --------    
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------




More information about the Numpy-discussion mailing list