Challenge - 5 Problems
2D Signal Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of 2D image array slicing
What is the output of the following code that slices a 2D image array?
Signal Processing
import numpy as np image = np.array([[10, 20, 30], [40, 50, 60], [70, 80, 90]]) slice_ = image[1:, :2] print(slice_)
Attempts:
2 left
💡 Hint
Remember that slicing [1:, :2] means rows from index 1 to end and columns from index 0 to 1.
✗ Incorrect
The slice image[1:, :2] selects rows starting from index 1 (second row) to the end, and columns from index 0 up to but not including 2 (first two columns). So it picks [[40, 50], [70, 80]].
❓ data_output
intermediateShape of a grayscale image array after resizing
Given a grayscale image represented as a 2D NumPy array of shape (256, 256), what will be the shape after resizing it to half the width and height using nearest neighbor?
Signal Processing
import numpy as np from skimage.transform import resize image = np.random.randint(0, 256, (256, 256), dtype=np.uint8) resized_image = resize(image, (128, 128), order=0, preserve_range=True).astype(np.uint8) print(resized_image.shape)
Attempts:
2 left
💡 Hint
Resizing to half width and height means both dimensions are halved.
✗ Incorrect
The original image is 256x256 pixels. Resizing to half width and height results in 128x128 pixels.
❓ visualization
advancedVisualizing a 2D sine wave as an image
Which option shows the correct code to generate and display a 2D sine wave image pattern using matplotlib?
Signal Processing
import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, 4 * np.pi, 100) y = np.linspace(0, 4 * np.pi, 100) X, Y = np.meshgrid(x, y) Z = np.sin(X) + np.sin(Y) plt.imshow(Z, cmap='gray') plt.colorbar() plt.show()
Attempts:
2 left
💡 Hint
The sum of sine waves in X and Y directions creates a grid pattern.
✗ Incorrect
Option D correctly creates a 2D sine wave pattern by summing sine values along X and Y axes and displays it in grayscale.
🔧 Debug
advancedIdentify the error in 2D convolution code
What error does the following code raise when trying to convolve a 2D image with a kernel using scipy.signal.convolve2d?
Signal Processing
import numpy as np from scipy.signal import convolve2d image = np.array([[1, 2], [3, 4]]) kernel = np.array([1, 0]) result = convolve2d(image, kernel) print(result)
Attempts:
2 left
💡 Hint
Check the shape of the kernel array passed to convolve2d.
✗ Incorrect
The kernel is 1D (shape (2,)) but convolve2d requires a 2D kernel. This causes a ValueError.
🚀 Application
expertCalculate the energy of a 2D signal image
Given a 2D NumPy array representing an image signal, which option correctly calculates the total energy (sum of squared pixel values)?
Signal Processing
import numpy as np image = np.array([[1, 2], [3, 4]])
Attempts:
2 left
💡 Hint
Energy is the sum of squares of all pixel values.
✗ Incorrect
Energy of a signal is the sum of squared values. Option B correctly computes this.
