[Matrix-SIG] array assignments
Michael Hudson
mwh21@cam.ac.uk
Thu, 7 Oct 1999 11:37:45 +0100 (BST)
Welcome to Python!
On Thu, 7 Oct 1999, Pedro Miguel Frazao Fernandes Ferreira wrote:
> Hi All,
>
> Can anyone tell me if this is the correct behaviour:
>
> Python 1.5.1 (#1, Dec 17 1998, 20:58:15) [GCC 2.7.2.3] on linux2
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> Executing startup script
> End
> >>> a=arange(10)
> >>> b=arange(10)
> >>> a=b
> >>> b[5]=10
> >>> print a
> [ 0 1 2 3 4 10 6 7 8 9]
> >>>
>
> Should a and b be two different objects ?
> = operator should copy ?
Absolutely not. (Well, that's a bit strong, but it is inherent in Python
that = doesn't copy).
There isn't really a "= operator" in Python. "a=b" is syntax for "bind the
name a to the object currently bound to the name b".
HTH
Michael