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


Groups > comp.lang.python > #105192 > unrolled thread

why x is changed in the following program?

Started by"maurice.charbit@telecom-paristech.fr" <maurice.charbit@telecom-paristech.fr>
First post2016-03-18 10:09 +0100
Last post2016-03-18 11:55 -0700
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  why x is changed in the following program? "maurice.charbit@telecom-paristech.fr" <maurice.charbit@telecom-paristech.fr> - 2016-03-18 10:09 +0100
    Re: why x is changed in the following program? Palpandi <palpandi111@gmail.com> - 2016-03-18 11:55 -0700

#105192 — why x is changed in the following program?

From"maurice.charbit@telecom-paristech.fr" <maurice.charbit@telecom-paristech.fr>
Date2016-03-18 10:09 +0100
Subjectwhy x is changed in the following program?
Message-ID<mailman.309.1458296628.12893.python-list@python.org>
from numpy import random
x=random.randn(6)
y=x
y[0]=12
print x[0]



Maurice Charbit
Emeritus Prof.
mob.: 33 (0)6 5230 1171
tel.: 33 (0)1 4581 7178
fax:  33 (0)1 4581 7144
maurice.charbit@telecom-paristech.fr <mailto:maurice.charbit@telecom-paristech.fr>
Adresse:
Institut Mines-Telecom,
46, rue Barrault, 75014 Paris

[toc] | [next] | [standalone]


#105233

FromPalpandi <palpandi111@gmail.com>
Date2016-03-18 11:55 -0700
Message-ID<fcf6013c-927f-4bcf-8324-b33df60fe4ea@googlegroups.com>
In reply to#105192
On Friday, March 18, 2016 at 3:53:58 PM UTC+5:30, maurice...@telecom-paristech.fr wrote:
> from numpy import random
> x=random.randn(6)
> y=x
> y[0]=12
> print x[0]
> 
> 
> 
> Maurice Charbit
> Emeritus Prof.
> mob.: 33 (0)6 5230 1171
> tel.: 33 (0)1 4581 7178
> fax:  33 (0)1 4581 7144
> maurice.charbit@telecom-paristech.fr <mailto:maurice.charbit@telecom-paristech.fr>
> Adresse:
> Institut Mines-Telecom,
> 46, rue Barrault, 75014 Paris

http://stackoverflow.com/questions/6793872/variable-assignment-and-modification-in-python

if 
a = 5
b = a
print id(a) == id(b)
>> False
b = 2
print a
>> 5

In this case we assigning the value to b.

But in the above case, we are assigning the same object reference. Like arrays in c.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web