Indexing NumPy arrays

Python for MATLAB Users

Justin Kiggins

Product Manager

Indexing with ranges

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

slice.shape
(5,)
Python for MATLAB Users

Indexing multidimensional arrays

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

window.shape
(50,100)
Python for MATLAB Users

Indexing with Boolean arrays

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

Let's practice!

Python for MATLAB Users

Preparing Video For Download...