Question
Similar to `get_is_row_inky`, Write the function `get_is_col_inky` that finds the columns with ink pixels and takes following the arguments: * `images`: A numpy array with
Similar to `get_is_row_inky`, Write the function `get_is_col_inky` that finds the columns with ink pixels and takes following the arguments: * `images`: A numpy array with the shape `(N,height,width)`, where * `N` is the number of samples and could be anything, * `height` is each individual image's height in pixels (i.e., number of rows in each image), * and `width` is each individual image's width in pixels (i.e., number of columns in each image). * **Note**: Do not assume anything about `images`'s dtype or the number of samples or the `height` or the `width`. and returns the following: * `is_col_inky`: A numpy array with the shape `(N, width)`, and the `bool` dtype. * `is_col_inky[i,j]` should be True if **any** of the pixels in the `j`th column of the `i`th image was an ink pixel, and False otherwise.
# get_is_row_inky() exp.
def get_is_row_inky(images): """ Finds the rows with ink pixels.
Parameters: images (np,array): A numpy array with the shape (N, height, width)
Returns: is_row_inky (np.array): A numpy array with the shape (N, height), and the bool dtype. """ is_row_inky = np.any(images, axis=2) return is_row_inky
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#REWRITE the code from below. IT MUST PASS THE ASSERTION, I GET THE ERROR IN THE IMAGE
def get_is_col_inky(images): """ Finds the columns with ink pixels.
Parameters: images (np.array): A numpy array with the shape (N,height,width). Returns: is_col_inky (np.array): A numpy array with the shape (N, width), and the bool dtype. """
#REPLACE THIS CODE BELOW TO PASS THE ASSERTION. IT KEEPS FAILING THE ASSERTION images = np.transpose(images, (0,2,1)) #transpose the image to put the columns in the axis 1
is_col_inky = np.any(images, axis=1)
return is_col_inky
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#Assertion
(orig_image, ref_image, test_im, success_is_col_inky) = show_test_cases(lambda x: np.expand_dims(get_is_col_inky(x), axis=1), task_id='3_V')
assert success_is_col_inky
--------------------------------------------------------------------------------------------------
#ASSERTION FAILURE FROM THE FUNCTION get_is_row_inky(images) CODE:
The reference and solution images are not the same... ref_image[0, 4]=False test_image[0, 4]=True I will return the images so that you will be able to diagnose the issue and resolve it...
---------------------------------------------------------------------------
BEWARE OF THIS ERROR AS WELL:
THAT RESULTS FROM DOING:
def get_is_col_inky(images): is_col_inky = np.any(images, axis=(1,2)) return is_col_inky
(orig_image, ref_image, test_im, success_is_col_inky) = show_test_cases(lambda x: np.expand_dims(get_is_col_inky(x), axis=1), task_id="3_v") assert success_is_col_inky Error: It seems the test images and the ref images have different shapes. Modify your function so that they both have the same shape. test_images shape: (100,1) ref_images shape: (100,1,28) Assertionerror 2 3 AssertionerrorStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started