
This will work: b=zeros ((3,3)) b[:2,:2] = b[:2,:2] + a[1:,1:] You need to know the size of a to use this scheme. ----- Original Message ----- From: "Chris Barker" <chrishbarker@home.net> To: "Mike Romberg" <romberg@fsl.noaa.gov> Cc: <numpy-discussion@lists.sourceforge.net> Sent: Monday, September 17, 2001 2:03 PM Subject: Re: [Numpy-discussion] Offset 2D arrays
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@home.net --- --- --- http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ ------@@@ ------@@@ ------@@@ Oil Spill Modeling ------ @ ------ @ ------ @ Water Resources Engineering ------- --------- -------- Coastal and Fluvial Hydrodynamics -------------------------------------- ------------------------------------------------------------------------
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/numpy-discussion