Pengindeksan array NumPy

Python untuk Pengguna MATLAB

Justin Kiggins

Product Manager

Indeks dengan rentang

arr.shape
(100,)
slice = arr[10:15]

slice.shape
(5,)
Python untuk Pengguna MATLAB

Mengindeks array multidimensi

image.shape
(1920, 1200)
window = image[100:150,1000:1100]

window.shape
(50,100)
Python untuk Pengguna MATLAB

Indeks dengan array Boolean

data.shape
(10000,)
is_valid.dtype
<np.bool>
np.sum(is_valid)
8732
valid_data = data[is_valid]
valid_data.shape
(8732,)
Python untuk Pengguna MATLAB

Ayo berlatih!

Python untuk Pengguna MATLAB

Preparing Video For Download...