數組索引能辦到的,切片都能辦到,只不過索引會降維,而切片不回改變維度,代碼:
純切片:
import numpy as np
boxes = np.array([[1,2,3,4],[5,6,7,8],[9,10,11,10]])
a = boxes[:,2:3]
print(boxes.shape)
print(a)
結果:
(3, 4)
[[ 3]
[ 7]
[11]]
切片家索引:
import numpy as np
boxes = np.array([[1,2,3,4],[5,6,7,8],[9,10,11,10]])
a = boxes[:,2]
print(boxes.shape)
print(a)
結果:
(3, 4)
[ 3 7 11]