From 6a86460bd968e3a4aea66efb4727ca90829d9c67 Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Tue, 29 Aug 2023 09:56:34 +0300 Subject: [PATCH 1/2] initial commit --- hands_on/local_maxima/local_maxima.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hands_on/local_maxima/local_maxima.py b/hands_on/local_maxima/local_maxima.py index db89ba3..8393dcc 100644 --- a/hands_on/local_maxima/local_maxima.py +++ b/hands_on/local_maxima/local_maxima.py @@ -7,4 +7,9 @@ def find_maxima(x): Output: idx -- list of indices of the local maxima in x """ - return [] + local_max = [] + diffs = [f-i for i,f in zip(v[0:-1],v[1:])] + for i in range(len(diffs)-1): + if diffs[i] > 0 and diffs[i+1] < 0: + local_max.append(i+1) + return local_max \ No newline at end of file From 4f2728974352c5716b1db290ec83721a45d899da Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Tue, 29 Aug 2023 10:02:03 +0300 Subject: [PATCH 2/2] updated commit --- hands_on/local_maxima/local_maxima.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/hands_on/local_maxima/local_maxima.py b/hands_on/local_maxima/local_maxima.py index 8393dcc..742c894 100644 --- a/hands_on/local_maxima/local_maxima.py +++ b/hands_on/local_maxima/local_maxima.py @@ -8,8 +8,11 @@ def find_maxima(x): idx -- list of indices of the local maxima in x """ local_max = [] - diffs = [f-i for i,f in zip(v[0:-1],v[1:])] + diffs = [f-i for i,f in zip(x[0:-1],x[1:])] for i in range(len(diffs)-1): if diffs[i] > 0 and diffs[i+1] < 0: local_max.append(i+1) - return local_max \ No newline at end of file + return local_max + +l = [] +print(find_maxima(l))