![]() | With a as list, a[:] makes a copy of the data |
![]() | With a as array, a[:] is a reference to the data
>>> b = a[1,:] # extract 2nd row of a >>> print a[1,1] 12.0 >>> b[1] = 2 >>> print a[1,1] 2.0 # change in b is reflected in a! |
![]() | Take a copy to avoid referencing via slices:
>>> b = a[1,:].copy() >>> print a[1,1] 12.0 >>> b[1] = 2 # b and a are two different arrays now >>> print a[1,1] 12.0 # a is not affected by change in b |