问题 I am trying to fit x y data which look something like x = np.linspace(-2, 2, 1000) a = 0.5 yl = np.ones_like(x[x < a]) * -0.4 + np.random.normal(0, 0.05, x[x < a].shape[0]) yr = np.ones_like(x[x >= a]) * 0.4 + np.random.normal(0, 0.05, x[x >= a].shape[0]) y = np.concatenate((yl, yr)) plt.scatter(x, y, s=2, color='k') I'm using a variation of the Heaviside step function def f(x, a, b): return 0.5 * b * (np.sign(x - a)) and fitting with popt, pcov = curve_fit(f, x, y, p0=p) where p is some