Numpy: slice - copy
import numpy as np
a = np.array([1, 1, 2, 3, 5, 8, 13, 21, 34])
print(a) # [ 1 1 2 3 5 8 13 21 34]
b = a[2:5].copy()
print(b) # [2 3 5]
a[2] = 20
print(a) # [ 1 1 20 3 5 8 13 21 34]
print(b) # [2 3 5]
Press ← or → to navigate between chapters
Press S or / to search in the book
Press ? to show this help
Press Esc to hide this help
import numpy as np
a = np.array([1, 1, 2, 3, 5, 8, 13, 21, 34])
print(a) # [ 1 1 2 3 5 8 13 21 34]
b = a[2:5].copy()
print(b) # [2 3 5]
a[2] = 20
print(a) # [ 1 1 20 3 5 8 13 21 34]
print(b) # [2 3 5]