Question: I need help with the createBox(box) function ASAP! Thank you!! 2) Problem 2: Stencils In this problem, we ask you to fill in the two

 I need help with the createBox(box) function ASAP! Thank you!! 2)Problem 2: Stencils In this problem, we ask you to fill inthe two functons in problem2.py : 1. stencil(data, f, width) : This

I need help with the createBox(box) function ASAP! Thank you!!

2) Problem 2: Stencils In this problem, we ask you to fill in the two functons in problem2.py : 1. stencil(data, f, width) : This function takes in a list, data , a function, f, and an int, width , and returns a list. This function returns the result (an output list of length k-width+1 ) of applying the stencil function f to the input list data as described in the Background section. 2. createBox(box) : This function accepts a list, box, and returns two outputs: a new function and a width (int). The width is the length of the box (the number of elements that the filter looks at). The new function is a stencil function that operates on len(box) items from an input list and applies a box filter to them as described in the Background section. The function should check, at the beginning, if the length in the input parmeter is the same as the length of box. If not, the following error should be printed: Calling box filter with the wrong length list. Expected length of list should be n. where n is the length of box. For example if n=7, the printed warning should be: Calling box filter with the wrong length list. Expected length of list should be 7. def stencil (data, f, width): II II II perform a stencil using the filter f with width w on list data output the resulting list note that if len(data) = k, len(output) = k - width + 1 will accept as input a list of size width and return a single number :param data: list :param f: function :param width: int :return: list II II II # Fill in pass def createBox (box): II II II create a box filter from the input list "box" this filter should accept a list of length len(box) and return a simple convolution of it. the meaning of this box filter is as follows: for each element the input list 1, multiple l[i] by box[i] sum the results of all of these multiplications return the sum So for a box of length 3, filter(1) should return: (box[0] * 1[0] + box[1] * 1[1] + box[2] * 1[2]). The function createBox returns the box filter itself, as well as the length of the filter (which can be passed as an argument to cony) :param box: list :return: function, int # Fill in def boxFilter(1): # Fill in pass return boxFilter, len(box) if __name ' __main__': def movAvg(1): if len(1) != 3: print(len(1)) print("Calling movAvg with the wrong length list") exit (1) return float(sum(1)) / 3 def sumSq(1): if len(1) != 5: print("Calling sumSq with the wrong length list") exit(1) return sum([i ** 2 for i in 1]) data = [2, 5, -10, -7, -7, -3, -1, 9, 8, -6] print(stencil(data, movAvg, 3)) print(stencil(data, sumSq, 5)) # note that this creates a moving average! boxF1, width1 = createBox([1.0 / 3, 1.0 / 3, 1.0 / 3]) print(stencil(data, boxF1, width1)) boxF2, width2 = createBox((-0.5, 0, 0, 0.5]) print(stencil(data, boxF2, width2))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!