Question: please use python 6. [2] Create a Python function array_log(a,b,oper) which has three arguments: a and b are numpy arrays of numbers, and oper (standing
![please use python 6. [2] Create a Python function array_log(a,b,oper) which](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f66fce35fef_50966f66fcdc35f2.jpg)

please use python
6. [2] Create a Python function array_log(a,b,oper) which has three arguments: a and b are numpy arrays of numbers, and oper (standing for operation) is a string. If oper equals 'add' the function returns the array whose entries are the sums of the logarithms of the corresponding entries in a and b i.e., log a[i,j]+log b[i,j]. If oper equals 'subtract' the function returns the array whose entries are the differences of the logarithms of the corresponding entries in a and b i.e., log a[i,j]-log b[i,j]. The function array_log(a,b,oper) should return the string Error if: (a) the string operation has a value other than 'add' or 'subtract', (b) the two arrays have different shapes, and (c) there is an entry in either a or b which is zero or negative. #Question 6 import numpy as np def array_log(a, b, oper): """ operations on matrices, if defined # test cases to try out: print(array_log(np. array([[1,2.34],[4,5]]), np.array([[1.0, 0],[2, 4]]),"add")) print(array_log(np.array([[1,2],[4,5]]), np.array([1,2]), "subtract")) print(array_log(np.array([[1,2],[4,5]]), np.array([[1,2],[2,4]]), "subtract")) print(array_log(np.array([[1,2],[4,5]]), np.array([[1,5),[2,6]]),"add")) print(array_log(np.array([[1,2],[4,5]]), np.array([[1,5],[2,6]]),"subtract")) print(array_log(np.array([[1,2],[4,5]]), np.array([[1,5],[2,6]]), "multiply"))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
