Challenge - 5 Problems
Image Array Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the shape of the image array?
Given a color image loaded as a NumPy array with shape (480, 640, 3), what does the shape represent?
NumPy
import numpy as np image = np.zeros((480, 640, 3)) print(image.shape)
Attempts:
2 left
💡 Hint
Remember the shape order is (height, width, channels) for images.
✗ Incorrect
The shape (480, 640, 3) means the image has 480 rows (height), 640 columns (width), and 3 color channels (Red, Green, Blue).
❓ data_output
intermediate1:30remaining
What is the pixel value at position (2, 3)?
Consider this grayscale image array:
import numpy as np
image = np.array([[10, 20, 30, 40],
[50, 60, 70, 80],
[90, 100, 110, 120]])
print(image[2, 3])
What is the output?NumPy
import numpy as np image = np.array([[10, 20, 30, 40], [50, 60, 70, 80], [90, 100, 110, 120]]) print(image[2, 3])
Attempts:
2 left
💡 Hint
Remember indexing is zero-based and rows come first.
✗ Incorrect
The pixel at row 2, column 3 is 120 because indexing starts at 0.
❓ visualization
advanced2:30remaining
Visualize a grayscale image from a 2D array
Which code snippet correctly displays a 5x5 grayscale image using matplotlib from a NumPy array?
NumPy
import numpy as np import matplotlib.pyplot as plt image = np.array([[0, 50, 100, 150, 200], [10, 60, 110, 160, 210], [20, 70, 120, 170, 220], [30, 80, 130, 180, 230], [40, 90, 140, 190, 240]]) plt.imshow(image, cmap='gray') plt.show()
Attempts:
2 left
💡 Hint
Use the grayscale colormap to show intensity properly.
✗ Incorrect
Using cmap='gray' tells matplotlib to display the array as a grayscale image.
🔧 Debug
advanced2:00remaining
Why does this code raise an error?
What error does this code raise and why?
import numpy as np image = np.zeros((100, 100, 3)) print(image[50, 50]) print(image[50, 50, 3])
NumPy
import numpy as np image = np.zeros((100, 100, 3)) print(image[50, 50]) print(image[50, 50, 3])
Attempts:
2 left
💡 Hint
Remember Python indexing starts at 0 and max index is size-1.
✗ Incorrect
The last index 3 is out of bounds because valid channel indices are 0, 1, 2.
🚀 Application
expert3:00remaining
Calculate average color of an RGB image
Given a NumPy array representing an RGB image of shape (100, 100, 3), which code correctly calculates the average color across all pixels?
NumPy
import numpy as np image = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8)
Attempts:
2 left
💡 Hint
Average color means average over height and width, keep channels separate.
✗ Incorrect
Using axis=(0,1) averages over rows and columns, leaving the 3 color channels.