CONVERT THIS MATLAB LANGUAGE TO WORK IN PYTHON function nexceed_array = exceed_c
ID: 668634 • Letter: C
Question
CONVERT THIS MATLAB LANGUAGE TO WORK IN PYTHON
function nexceed_array = exceed_consecutive(array, threshold)
is_consecutive = 0;
n = 0;
nexceed_array = [];
for i = 1:length(array)
if array(i) > threshold
n = n + 1;
is_consecutive = 1;
else
if is_consecutive
nexceed_array(end+1) = n;
n = 0;
is_consecutive = 0;
end
end
end
if array(end) > threshold
if length(nexceed_array) == 0
nexceed_array = 0;
end
Explanation / Answer
Please find the converted code below
@mfunction("nexceed_array")
def exceed_consecutive(array=None, threshold=None):
is_consecutive = 0
n = 0
nexceed_array = mcat([])
for i in mslice[1:length(array)]:
if array(i) > threshold:
n = n + 1
is_consecutive = 1
else:
if is_consecutive:
nexceed_array(end + 1).lvalue = n
n = 0
is_consecutive = 0
end
end
end
if array(end) > threshold:
if length(nexceed_array) == 0:
nexceed_array = 0
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.