1. Write a function called yLim which takes as input the vectors r and y. This f
ID: 3579758 • Letter: 1
Question
1. Write a function called yLim which takes as input the vectors r and y. This function returns a vector of length 2, which contains the values in y that occur in the positions of the minimum and maximum values of r. That is, x c (100, 13, 1, 20) y c (5 7, 9, 0) y Lim (x, y) [1] 9 5 Since the minimum of is in the 3rd element of z maximum of z (which are 9 and in position, the return value is vector containing the 3rd and first values in y a 5, respectively). is shorter than y, Additionally, the input z is required, and u has a default value of r. If then a message should be issued but the computation is carried out. shorter than r, then the function is erminated and a message issued. You may assume that there is a is minimum and maximum in z and there are no As in either a or yExplanation / Answer
import numpy as np
def yLim(x, y):
min = float('Inf')
max = float('-Inf')
mini = 0
maxi = 0
if len(x)>len(y):
print "The length of x is greater than y."
return
else:
if len(y)>len(x):
print "The length of y is greater than x."
for i in range(len(x)):
if x[i]>max:
max = x[i]
maxi = i
if x[i]<min:
min = x[i]
mini = i
return y[mini], y[maxi]
x = [100, 13, 1, 20]
y = [5, 7, 9, 0]
ans = yLim(x, y)
print ans[0], ans[1]
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.