Complete the code to create a 3x3 grayscale image as a NumPy array.
import numpy as np image = np.array([1])
The image is represented as a 2D array with 3 rows and 3 columns, each value representing a pixel intensity.
Complete the code to access the pixel value at row 1, column 2 in the image array.
pixel_value = image[[1]]NumPy arrays use tuple indexing for multi-dimensional access like image[row, column].
Fix the error in the code to convert a color image array to grayscale by averaging the color channels.
grayscale = np.mean(image[1], axis=[2])
To average color channels, select all rows and columns and all color channels with [:, :, :], then take mean along axis 2.
Fill both blanks to create a dictionary mapping pixel positions to their grayscale values for pixels with value greater than 100.
pixel_dict = [1] for i in range(image.shape[0]) for j in range(image.shape[1]) if image[i, j] [2] 100
This dictionary comprehension creates keys as pixel coordinates and values as pixel intensities for pixels above 100.
Fill all three blanks to create a new image array where pixels below 50 are set to 0, others remain unchanged.
new_image = np.array([[image[i, j] if image[i, j] [1] 50 else [2] for j in range([3])] for i in range(image.shape[0])])
The code uses a nested list comprehension to check each pixel; if pixel is greater than 50, keep it, else set to 0. The inner loop runs over columns using image.shape[1].