đźŤľ Xarray is now 10 years old! đźŽ‰

xarray.DataArray.polyfit#

DataArray.polyfit(dim, deg, skipna=None, rcond=None, w=None, full=False, cov=False)[source]#

Least squares polynomial fit.

This replicates the behaviour of numpy.polyfit but differs by skipping invalid values when skipna = True.

Parameters:
• dim (`Hashable`) â€“ Coordinate along which to fit the polynomials.

• deg (`int`) â€“ Degree of the fitting polynomial.

• skipna (`bool` or `None`, optional) â€“ If True, removes all invalid values before fitting each 1D slices of the array. Default is True if data is stored in a dask.array or if there is any invalid values, False otherwise.

• rcond (`float` or `None`, optional) â€“ Relative condition number to the fit.

• w (`Hashable`, array-like or `None`, optional) â€“ Weights to apply to the y-coordinate of the sample points. Can be an array-like object or the name of a coordinate in the dataset.

• full (`bool`, default: `False`) â€“ Whether to return the residuals, matrix rank and singular values in addition to the coefficients.

• cov (`bool` or `"unscaled"`, default: `False`) â€“ Whether to return to the covariance matrix in addition to the coefficients. The matrix is not scaled if cov=â€™unscaledâ€™.

Returns:

polyfit_results (`Dataset`) â€“ A single dataset which contains:

polyfit_coefficients

The coefficients of the best fit.

polyfit_residuals

The residuals of the least-square computation (only included if full=True). When the matrix rank is deficient, np.nan is returned.

[dim]_matrix_rank

The effective rank of the scaled Vandermonde coefficient matrix (only included if full=True)

[dim]_singular_value

The singular values of the scaled Vandermonde coefficient matrix (only included if full=True)

polyfit_covariance

The covariance matrix of the polynomial coefficient estimates (only included if full=False and cov=True)