Boolean indexing is indexing based on a Boolean array and falls in the family of fancy indexing. Since Boolean indexing is a kind of fancy indexing, the way it works is essentially the same.
The following is the code for this segment (refer to boolean_indexing.py
in this book's code bundle):
import scipy.misc import matplotlib.pyplot as plt import numpy as np face = scipy.misc.face() xmax = face.shape[0] ymax = face.shape[1] face=face[:min(xmax,ymax),:min(xmax,ymax)] def get_indices(size): arr = np.arange(size) return arr % 4 == 0 face1 = face.copy() xindices = get_indices(face.shape[0]) yindices = get_indices(face.shape[1]) face1[xindices, yindices] = 0 plt.subplot(211) plt.imshow(face1) face2 = face.copy() face2[(face > face.max()/4) & (face < 3 * face.max()/4)] = 0 plt.subplot(212) plt.imshow(face2) ...