I have seen examples where slope, yintercept = numpy.polyfit(x,y,1)
is used to return slope and y-intercept, but the documentation does not mention "slope" or "intercept" anywhere.
The documentation also states three different return options:
p: ndarray, shape (deg + 1,) or (deg + 1, K)
Polynomial coefficients, highest power first. If y was 2-D, the coefficients for k-th data set are in p[:,k],
or
residuals, rank, singular_values, rcond
These values are only returned if full == True
or
v: ndarray, shape (deg + 1, deg + 1) or (deg + 1, deg + 1, K)
Present only if full == False and cov == True
I have also run code with exactly the previous line and the slope
and yintercept
variables are filled with a single value each, which does not fit any of the documented returns. Which documentation am I supposed to use, or what am I missing?
slope, yintercept = numpy.polyfit(x, y, 1)
Both full and cov parameters are False
, so it's the first option, "Polynomial coefficients, highest power first". deg is 1, so "p: ndarray, shape (deg + 1,)" is an array of shape (2,).
With tuple assignment,
slope
is p[0]
, the xdeg-0 = x1 coefficient,yintercept
is p[1]
, the xdeg-1 = x0 coefficient.