[Numpy-discussion] Can not update a submatrix
Charles R Harris
charlesr.harris at gmail.com
Wed Jan 30 10:27:34 EST 2008
On Jan 30, 2008 8:21 AM, Nadav Horesh <nadavh at visionsense.com> wrote:
> But:
>
>
> >>> R[ax,:] = 100
> >>> R
> array([[ 0, 1, 2],
> [100, 100, 100],
> [100, 100, 100]])
> >>> R[:,ax] = 200
> >>> R
> array([[ 0, 200, 200],
> [100, 200, 200],
> [100, 200, 200]])
>
> Do I get an array view only if the array is contiguous?
>
You get an array view if the elements can be addressed with offsets,
strides, and counts. Think nested for loops.
In [1]: a = zeros((4,4))
In [2]: a[::2,::2] = 1
In [3]: a
Out[3]:
array([[ 1., 0., 1., 0.],
[ 0., 0., 0., 0.],
[ 1., 0., 1., 0.],
[ 0., 0., 0., 0.]])
Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20080130/eddfdae2/attachment.html>
More information about the NumPy-Discussion
mailing list