I am trying to implement an 1D peak algorithm in python, though I am having troubles implementing it. The idea is that it compares the central term of the array and picks the side with the higher neighbour term. That half becomes the new array. Only when the central is the largest term, does it become the peak. Here is my code: import math
import math
array = [1,2,3,4,5,6,7]
size = len(array)
count = 0
while count == 0:
if len(array) == 2:
count += 1
print(max(array[0],array[1]))
break
elif count == 0:
elif array[math.floor(abs(size/2))] < array[math.floor(abs(size/2))-1]:
new_array = []
for i in range(int(abs(size)/2)):
new_array.append(array[i])
array = new_array
elif array[math.floor(abs(size/2))] < array[math.floor(abs(size/2))+1]:
new_array = []
for j in range(math.floor(abs(size)/2),size):
new_array.append(array[j])
array = new_array
elif count == 0:
count += 1
print(array[math.floor(abs(size/2))])
break
I keep on getting errors, and I can not seem to identify the problem. Can anyone help out?