From: Karol L. <kar...@kn...> - 2006-06-14 09:50:44
|
On Wednesday 14 June 2006 11:14, Martin Wiechert wrote: > is there a concise way to address a subrectangle of a 2d array? So far I'm > using > > A [I] [:, J] > > which is not pretty and more importantly only works for reading the > subrectangle. Writing does *not* work. (Cf. session below.) > > Any help would be appreciated. > > Thanks, > Martin You can also use A[m:n,r:s] to refernce a subarray. =46or instance: >>> a =3D numpy.zeros((5,5)) >>> b =3D numpy.ones((3,3)) >>> a[1:4,1:4] =3D b >>> a array([[0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0], [0, 0, 0, 0, 0]]) Cheers, Karol =2D-=20 written by Karol Langner =B6ro cze 14 11:49:35 CEST 2006 |