code: def fitPlaneLSQ(XYZ):
      
      [rows,cols] = XYZ.shape
      G = np.ones((rows,3))
      G[:,0] = XYZ[:,0]  #X
      G[:,1] = XYZ[:,1]  #Y
      Z = XYZ[:,2]
      coeff,resid,rank,s = np.linalg.lstsq(G,Z,rcond=None)
      return coeff
docs: Fit a plane to input point data using LSQ