numpy array assignment problem
- by Sujan
Hi All:
I have a strange problem in Python 2.6.5 with Numpy. I assign a numpy array, then equate a new variable to it. When I perform any operation to the new array, the original's values also change. Why is that? Please see the example below. Kindly enlighten me, as I'm fairly new to Python, and programming in general.
-Sujan
>>> import numpy as np
>>> a = np.array([[1,2],[3,4]])
>>> b = a
>>> b
array([[1, 2],
[3, 4]])
>>> c = a
>>> c
array([[1, 2],
[3, 4]])
>>> c[:,1] = c[:,1] + 5
>>> c
array([[1, 7],
[3, 9]])
>>> b
array([[1, 7],
[3, 9]])
>>> a
array([[1, 7],
[3, 9]])