Question: Your task is to write a Python function q 2 _ func with the following def line: def q 2 _ func ( x ,

Your task is to write a Python function q2_func with the following def line:
def q2_func(x,y):
The function inputs x and y are assumed to be 1-dimensional numpy arrays of the same shape. The function is required to compute and return a numpy array which has the same shape as both x and y. In the following description, we will refer to the numpy array to be returned by the variable name z.
Let x[i], y[i] and z[i] be the element indexed by i in, respectively, the arrays x, y and z.
The relationship between x[i], y[i] and z[i] is given by the following pseduo-code:
if (absolute value of x[i]> absolute value of y[i]) z[i]= x[i]- y[i]/2 else z[i]= y[i]- x[i]/2
For examples:
If x[i] is 4 and y[i] is 3, then z[i] should take on the value of 432=2.5.
If x[i] is 3 and y[i] is -4, then z[i] should take on the value of 432=5.5.

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!