why x is changed in the following program?

Peter Otten __peter__ at web.de
Fri Mar 18 06:37:16 EDT 2016


maurice.charbit at telecom-paristech.fr wrote:

> from numpy import random
> x=random.randn(6)

In Python 

> y=x

doesn't make a copy, it binds y to the same object as x. From now on every 
modification you apply to y

> y[0]=12

 affects x, too, because x and y refer to the same object.

> print x[0]





More information about the Python-list mailing list