In most situations, real-life data is noisy and messy. It contains lots of gaps or missing characters in the data. Masked arrays are helpful in such cases and handle the issue. Masked arrays may contain invalid and missing values. The numpy.ma subpackage offers all the masked array-required functionality. In this section of the chapter, we will use the face image as the original image source and perform log mask operations.
Have a look at the following code block:
# Import required library
import numpy as np
from scipy.misc import face
import matplotlib.pyplot as plt
face_image = face()
mask_random_array = np.random.randint(0, 3, size=face_image.shape)
fig, ax = plt.subplots(nrows=2, ncols=2)
# Display the Original Image
plt.subplot(2,2,1)
plt.imshow(face_image)
plt.title("Original Image")
plt.axis('off')
# Display masked array
masked_array = np.ma.array(face_image, mask=mask_random_array)
plt.subplot(2,2,2)
plt.title("Masked...