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.
Given below is a robust approach:
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)