Complete the code to load an image as a 2D array using numpy.
import numpy as np image = np.[1]('image_data.txt')
np.array directly on a filename causes an error.open returns a file object, not an array.We use np.loadtxt to load image data from a text file into a 2D numpy array.
Complete the code to get the shape of the 2D image array.
height, width = image.[1]size returns total elements, not shape.len returns only the first dimension.The shape attribute gives the dimensions of a numpy array as (rows, columns).
Fix the error in the code to access the pixel value at row 10, column 15.
pixel_value = image[[1]][15]
To access a pixel at row 10 and column 15, use image[10][15] or image[10, 15].
Fill both blanks to create a dictionary of pixel intensities for pixels with values greater than 100.
bright_pixels = {(row, col): image[row, col] for row in range(image.[1]) for col in range(image.shape[1]) if image[row, col] [2] 100}size instead of shape[0] for rows.We use shape[0] for rows and check if pixel value is greater than 100.
Fill all three blanks to create a dictionary of pixel intensities for pixels with values less than 50.
dark_pixels = {(row, col): image[row, col] for row in range(image.[1]) for col in range(image.[2]) if image[row, col] [3] 50}size instead of shape dimensions.We loop over rows and columns using shape[0] and shape[1], and filter pixels less than 50.
