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
- residuals: sum of squared residuals of the least squares fit
- rank: the effective rank of the scaled Vandermonde
- singular_values: singular values of the scaled Vandermonde
- rcond: value of rcond,
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?
0
<code>slope, yintercept = numpy.polyfit(x, y, 1)</code><code>slope, yintercept = numpy.polyfit(x, y, 1) </code>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
isp[0]
, the xdeg-0 = x1 coefficient,yintercept
isp[1]
, the xdeg-1 = x0 coefficient.
2