Bird
0
0

What will the following code display?

medium📝 Predict Output Q13 of 15
Matplotlib - Image Display
What will the following code display?
import matplotlib.pyplot as plt
import numpy as np
img = np.array([[0, 1], [1, 0]])
plt.imshow(img, cmap='gray')
plt.show()
AA 2x2 image with black and white pixels
BA line plot of the array values
CAn error because cmap='gray' is invalid
DA blank plot with no image
Step-by-Step Solution
Solution:
  1. Step 1: Understand the array and cmap

    The array has values 0 and 1 arranged in a 2x2 grid. Using cmap='gray' maps 0 to black and 1 to white.
  2. Step 2: Predict the image output

    The image will show a 2x2 grid with black and white pixels arranged as per the array.
  3. Final Answer:

    A 2x2 image with black and white pixels -> Option A
  4. Quick Check:

    Array + cmap='gray' = black/white image [OK]
Quick Trick: cmap='gray' shows 0 as black, 1 as white [OK]
Common Mistakes:
  • Expecting a line plot instead of image
  • Thinking cmap='gray' causes error
  • Assuming image will be blank

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes