[Numpy-discussion] advanced indexing question
David Kershaw
dskgair at gmail.com
Wed Feb 4 02:22:48 EST 2015
The numpy reference manual, array objects/indexing/advance indexing,
says:
Advanced indexing always returns a copy of the data (contrast with
basic slicing that returns a view).
If I run the following code:
import numpy as np
d=range[2]
x=np.arange(36).reshape(3,2,3,2)
y=x[:,d,:,d]
y+=1
print x
x[:,d,:,d]+=1
print x
then the first print x shows that x is unchanged as it should be since y
was a copy, not a view, but the second print x shows that all the elements
of x with 1st index = 3rd index are now 1 bigger. Why did the left side of
x[:,d,:,d]+=1
act like a view and not a copy?
Thanks,
David
More information about the NumPy-Discussion
mailing list