I have a graph that looks like a letter "L" in the mirror or like this: ___/ The slope of first part of the graph is +/-0 (but it is not zero!) and I would like to define the exact point, where the graph starts to bend (slope > 0.).
path = '/storage/.../01_python_in/'
test = np.loadtxt(path+'sample_data.txt', skiprows=0)
window = 10
slope_value = []
for j in range(len(test) - window):
slope, intercept, r_value, p_value, std_err = stats.linregress(test[j:j+window])
if slope > 0.2:
slope_value.append(slope)
print slope
else:
slope_value.append(0)
This works ok, whereas I have two issues:
1) My output is an array of slopes for i+10 elements. How can I find out what is the index of the first element that is not zero, so I can read out the data point in my 'test" data (sorry, this is basic, but I'm a python-newbie)? 2) My actual data doesn't look perfectly linear as it contains some noise. My solution has two variables ('window' and slope > 0.2), which I can only guess (estimate). Is there a more elegant solution maybe? Thanks for helping!