[Numpy-discussion] addressing a submatrix
Simon Burton
simon at arrowtheory.com
Wed Jun 14 14:25:55 EDT 2006
On Wed, 14 Jun 2006 11:14:17 +0200
Martin Wiechert <martin.wiechert at gmx.de> wrote:
>
> Hi list,
>
> is there a concise way to address a subrectangle of a 2d array? So far I'm
> using
>
> A [I] [:, J]
what about A[I,J] ?
Simon.
>>> import numpy
>>> a=numpy.zer
numpy.zeros numpy.zeros_like
>>> a=numpy.zeros([4,4])
>>> a
array([[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]])
>>> a[2:3,2:3]=1
>>> a
array([[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 0]])
>>> a[1:3,1:3]=1
>>> a
array([[0, 0, 0, 0],
[0, 1, 1, 0],
[0, 1, 1, 0],
[0, 0, 0, 0]])
>>>
--
Simon Burton, B.Sc.
Licensed PO Box 8066
ANU Canberra 2601
Australia
Ph. 61 02 6249 6940
http://arrowtheory.com
More information about the NumPy-Discussion
mailing list