c
! www.simula.no/˜hpl
Slices refer the array data
With a as list, a[:] makes a copy of the data
With a as array, a[:] is a reference to the data
>>> b = a[2,:] # extract 2nd row of a
>>> print a[2,0]
12.0
>>> b[0] = 2
>>> print a[2,0]
2.0 # change in b is reflected in a!
Ta ke a c o py t o avo i d r e fe r e n c i n g v i a s l i c e s :
>>> b = a[2,:].copy()
>>> print a[2,0]
12.0
>>> b[0] = 2 # b and a are two different arrays now
>>> print a[2,0]
12.0 # a is not affected by change in b
Numerical Python – p. 251/728
Komentáře k této Příručce