title: FInd all intersections of xy data point graph with numpy?
body: <p>I am analyzing data from cyclic tensile tests. As input are used <em>huge</em> lists of x and y values.
  To describe if the material hardens or softens, I need to get the blue slope of each cycle loop.</p>
  
  <p><img src="https://i.stack.imgur.com/wb3CF.png" alt="tensile_test"></p>
  
  <p><img src="https://i.stack.imgur.com/Qjjr2.png" alt="slope"></p>
  
  <p>Getting the lower point of slope is child festival, but the upper one, that is the challenge.</p>
  
  <p><img src="https://i.stack.imgur.com/ETHpl.png" alt="the_challenge"></p>
  
  <p>I have made this approach so far, slicing out the loops with few points below local maximum of each loop and making the red lines from <em>hardnumbered</em> count of points. Aproximation of red lines is made by <code>poly1d(polyfit(x1,x2,1))</code> and <code>fsolve</code> is used then to get the intersection point. However it does not works always correctly, because the distribution of points is not always the same.</p>
  
  <p><img src="https://i.stack.imgur.com/uX4te.png" height="500"></p>
  
  <p>The problem is how to <em>correctly define the interval</em> of two (red) intersecting lines. In the picture above are 3 experiments together with averaged slope. I spent few days trying to find 4 closest points for each loop deciding this is not the best approach. And finally, I ended here at stackowerflow.</p>
  
  <p>Desired output is list with approximate coordinates of intersection points - if you want to play, <a href="http://bit.ly/1cgP7A0" rel="nofollow noreferrer">here</a> are data for the curve (0,[[xvals],[yvals]]). Theese can be easily read with </p>
  
  <pre><code>import csv
  import sys
  csv. field_size_limit(sys.maxsize)     
  
  csvfile = 'data.csv'
  tc_data = {}
  for key, val in csv.reader(open(csvfile, "r")):
      tc_data[key] = val
  for key in tc_data:
    tc = eval(tc_data[key])
  
  x = tc[0]
  y = tc[1]
  </code></pre>