More about references to data

>>> A = array([[1,2,3],[4,5,6]], float)
>>> print A
[[ 1.  2.  3.]
 [ 4.  5.  6.]]
>>> b = A[:,1:]
>>> print b
[[ 2.  3.]
 [ 5.  6.]]
>>> c = 3*b
>>> b[:,:] = c  # this affects A!
>>> print A
[[  1.   6.   9.]
 [  4.  15.  18.]]
>>> b = 2*c            # b refers to new array
>>> b[0,0] = -1        # does not affect A
>>> print A[0,0]
1.0
>>> A[:,:-1] = 3*c     # does not affect b
>>> print A
[[ 18.  27.   9.]
 [ 45.  54.  18.]]

previousnexttable of contents