• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Array elements within a function aren't able to change?
#1
[color=var(--highlight-color)]a = np.array([0,2,4,2,0,2,3,2,3,2,0])

plt.figure(figsize=(10,7))

plt.plot(a,label='a')



def raycrit(a,thresh):

? ? min_ind = argrelextrema(a, np.less)

? ? max_ind = argrelextrema(a, np.greater)

? ? maxima = a[max_ind]

? ? minima = a[min_ind]

? ? if min_ind[0][0] > max_ind[0][0]:

? ? ? ? for i in range(0,len(minima)):

? ? ? ? ? ? if maxima[i] > thresh and maxima[i] > thresh:

? ? ? ? ? ? ? ? if minima[i] > maxima[i]/2 and minima[i] > maxima[i]/2:

? ? ? ? ? ? ? ? ? ? minima[i] = thresh

? ? a[min_ind] = minima

? ? return a

? ? ? ?

b = raycrit(a,2.5)
[/color]



In the above code excerpt, I am trying to find local minima surrounded by local maxima that are more than half the height of the highest local maximum that neighbours it. And while this put into text might be confusing, I think reading the code helps understand what I'm trying to reach for. The problem arises with the fact that?

minima[i] = thresh

?stays unchanged even when the condition is triggered. Here the result should be [0,2,4,2,0,2,3,2.5,3,2,0] but remains [0,2,4,2,0,2,3,2,3,2,0] and I am quite confused as to why...








  Reply


Messages In This Thread
Array elements within a function aren't able to change? - by klausfelix - 2021-06-01, 05:00 PM

Forum Jump: