title: Line equation of every two consecutive points in a NumPy array
body: <p>I want to find the line equation of every two consecutive points (2-dimensional) in a NumPy array. I know how to do it robustly (i.e. using a loop), but I wonder if there's a more sophisticated approach.</p>
  <p>Thanks.</p>
  <p>Given below is a robust approach:</p>
  <pre><code>import numpy as np
  
  a = np.array([[1, 2], [2, 4], [3, 8], [5, 1]])
  N = int(max(a.shape))
  b = []
  for i in range(N - 1):
      x = [a[i,0], a[i + 1,0]]
      y = [a[i,1], a[i + 1,1]]
      b.append(tuple(np.polyfit(x, y, 1)))
  
  print(b)
  </code></pre>