Burgershot
  • Home
  • Members
  • Team
  • Help
  • Search
  • Register
  • Login
  • Home
  • Members
  • Help
  • Search
Burgershot General Programming Array elements within a function aren't able to change?

 
  • 0 Vote(s) - 0 Average
Array elements within a function aren't able to change?
klausfelix
Offline

Burgershot Member
Posts: 1
Threads: 1
Joined: Jun 2021
Reputation: 0
Location: united states
#1
2021-06-01, 05:00 PM
[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+1] > thresh:
                if minima[i] > maxima[i]/2 and minima[i] > maxima[i+1]/2:
                    minima[i] = thresh
    a[min_ind] = minima
    return a
       
b = raycrit(a,2.5)
[/color]

[font=-apple-system, BlinkMacSystemFont, "Segoe UI", "Liberation Sans", sans-serif]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...
[/font]




First Motion Products
« Next Oldest | Next Newest »



  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Burgershot - Powered by our Community and MyBB Original Theme by Emerald

Linear Mode
Threaded Mode