Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Analysis Using SQL And Excel

Authors: Gordon S Linoff

2nd Edition

111902143X, 9781119021438

More Books

Students also viewed these Databases questions