I'm trying to write code for a force test that will output the maximum force before structural failure occurs. I'm a bit of a novice to python, so the issue here might be something simple that I'm missing. Essentially, when I run the code, it will run indefinitely without outputting any value (so far, the longest I've let it run is about 10 minutes). I've been using a fake data frame with a vector length of about 80, so I think it must be an issue with the code rather than an issue of my vector being too long/requiring a long processing time.
Here's the code:
def find_new_max(data):
n=5
a=1
groups=np.array_split(data['Force'], len(data['Force'])//n)
slope=[group.max() - group.min() for group in groups[0:a]]
while np.all(np.array(slope)) > 0:
a=a+1
return(max(data['Force'][0:a*n]))
find_new_max(df)
Essentially, the goal is to have the code analyze slope by looking at groups consisting of five data points each, starting with just the first group, and then moving on to the consecutive group if a negative slope is not identified. Once it finds a negative slope, the loop should stop, and it should use the new "a" value to search the vector up to the group with the negative slope for a maximum value.
I'm not quite sure what's wrong here, as no errors are popping up. I've also tried to have it search only one group at a time like this:
def find_new_max(data):
n=5
b=0
a=1
groups=np.array_split(data['Force'], len(data['Force'])//n)
slope=[group.max() - group.min() for group in groups[b:a]]
while np.all(np.array(slope)) > 0:
b=b+1
a=a+1
return(max(data['Force'][0:a*n]))
find_new_max(df)
But the same problem occurs.
Any help is appreciated, thank you!
a
, but since you are not recalculating the value ofslope
the value for thewhile
statement does not change, causing it to always be true and therefore run indefinitely. $\endgroup$slope=[group.max() - group.min() for group in groups[:a]]
under thewhile
statement to ensure that the value ofslope
is also changing asa
updates, but the problem persists. $\endgroup$group.max()
andgroup.min()
, which would always yeild a positive number. Just switched togroup[-1]
andgroup[0]
respectively and it works. $\endgroup$