Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #105194

Re: why x is changed in the following program?

From Peter Otten <__peter__@web.de>
Newsgroups comp.lang.python
Subject Re: why x is changed in the following program?
Date 2016-03-18 11:37 +0100
Organization None
Message-ID <mailman.311.1458297456.12893.python-list@python.org> (permalink)
References <81574A74-81F6-44F3-8A42-EC3B12A2A399@telecom-paristech.fr>

Show all headers | View raw


maurice.charbit@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]

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: why x is changed in the following program? Peter Otten <__peter__@web.de> - 2016-03-18 11:37 +0100

csiph-web