From 8ae15bf2a54fbe83f46756947cf7e366f1482277 Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Tue, 23 Sep 2025 15:21:50 +0300 Subject: [PATCH] find local maxima --- hands_on/local_maxima/local_maxima.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hands_on/local_maxima/local_maxima.py b/hands_on/local_maxima/local_maxima.py index cfd0a9e..37548e9 100644 --- a/hands_on/local_maxima/local_maxima.py +++ b/hands_on/local_maxima/local_maxima.py @@ -7,9 +7,13 @@ def find_maxima(x): Output: idx -- list of indices of the local maxima in x """ - return [] + idx = [] + for i in range(1, len(x)-1): + if (x[i] > x[i-1]) & (x[i] > x[i+1]): + idx.append(i) + return idx if __name__ == "__main__": - x = [1, 2, 3] + x = [1, 3, -2, 0, 2, 1] print(find_maxima(x))