[Numpy-discussion] bug or feature?
Perry Greenfield
perry at stsci.edu
Mon Jul 11 10:53:35 EDT 2005
On Jul 11, 2005, at 1:38 PM, Curzio Basso wrote:
> Hi all,
>
> I noticed the following (unexpected for me) behaviour:
>
>>>> a = NA.arange(12)
>>>> a.shape = (3,4)
>>>> a[[0,2]][:,:2] = a[[0,2]][:,2:]
>>>> print a
> array([[ 0, 1, 2, 3],
> [ 4, 5, 6, 7],
> [ 8, 9, 10, 11]])
>
> rather than
>
> array([[ 2, 3, 2, 3],
> [ 4, 5, 6, 7],
> [ 10, 11, 10, 11]])
>
> as I was expecting. This happens only if I try to combine indices
> lists with slices.
> Is it by design or I ran into a bug?
>
> curzio
>
An array used as an index produces a new copy (if you think about it,
given the possibilities, there isn't much else that can be done). So
the entity on the left of your expression is modified, but since
nothing refers to it, it is discarded immediately thereafter. The array
'a' itself was never changed. I'd say that it isn't either a bug or
feature.
Perry Greenfield
More information about the NumPy-Discussion
mailing list