Text: Python
i) Produce a Python function array_log(a, b, operation) that has three arguments: a and b that are numpy arrays of numbers, and operation which is a string variable. If operation equals "log_addition" the function returns the array whose entries are the sums of the logarithms of a and b entries, i.e., log[i,j]+ logb[i,j]. If operation equals "log_subtraction" the function returns the array whose entries are the differences of the logarithms of a and b entries, i.e., log [i, j] - log b[i, j]. The function should return the string "Error" if: 1. the string operation has a value other than "log_addition" or "log_subtraction" 2. the two arrays have different shapes. 3. any of a and b have 0 or negative entries.
Provide 3 test cases to illustrate the 3 types of error outlined above. Provide 1 test case in which the function returns an array and operation is "log_addition". Provide 1 test case in which the function returns an array and operation is "log_subtraction".
ii) Produce a function array_change(a, change_val, new_val) that has three arguments: a that is a numpy array whose entries are numbers, and change_val and new_val that are numbers. The function returns a new array after changing every occurrence of the change_val in a to new_val.
Test Cases:
1) When c = np.array([4,2,3]), then array_change(c, 2, 0) should return [4, 0, 3].
2) When d = np.array([4,5,3]), then array_change(d, 6, 0) should return [4, 5, 3].