From: Herbert L. R. <roi...@ha...> - 2001-09-18 17:56:25
|
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" <chr...@ho...> To: "Mike Romberg" <ro...@fs...> Cc: <num...@li...> 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. > Chr...@ho... --- --- --- > http://members.home.net/barkerlohmann ---@@ -----@@ -----@@ > ------@@@ ------@@@ ------@@@ > Oil Spill Modeling ------ @ ------ @ ------ @ > Water Resources Engineering ------- --------- -------- > Coastal and Fluvial Hydrodynamics -------------------------------------- > ------------------------------------------------------------------------ > > _______________________________________________ > Numpy-discussion mailing list > Num...@li... > https://lists.sourceforge.net/lists/listinfo/numpy-discussion > |