The document says:
cov : bool, optional
Return the estimate and the covariance matrix of the estimate If full is True, then cov is not returned.
So set cov=True
and full=False
(default setting) will return the convariance matrix.
Question
When fitting a straight line to a set of data, weighted with errors, I was expecting polyfit to return a 2x2 covariance matrix from which I could square root the diagonal elements to find the uncertainty in the coefficients, but I don't.
Here's a minimum working example:
from numpy import polyfit
x=[1.,2.,3.,4.,5.,6.,7.,8.,9.]
y=[1.,3.,2.,4.,5.,6.,6.,8.,9.]
yerr=[10.,5.,3.,2.,10.,10.,10.,10.,10.]
linear = polyfit(x,y, 1, w=yerr, full=True)
print(linear)
With output:
(array([ 0.95730623, 0.11546722]), array([ 114.79556527]), 2, array([ 1.38182992, 0.30090875]), 1.9984014443252818e-15)
Thanks!
Solution
The document says:
cov : bool, optional
Return the estimate and the covariance matrix of the estimate If full is True, then cov is not returned.
So set cov=True
and full=False
(default setting) will return the convariance matrix.