numpy.ma.polyfit#
- ma.polyfit(x, y, deg, rcond=None, full=False, w=None, cov=False)[source]#
Least squares polynomial fit to data with possible masked values.
This function is the equivalent of
numpy.polyfitthat takes masked values into account, seenumpy.polyfitfor details.See also
numpy.polyfitEquivalent function for ndarrays.
Notes
Any masked values in x are propagated to y, and vice-versa. A data point is excluded from the fit if either coordinate is masked.
Examples
>>> import numpy as np
Fit a line to data with a masked outlier in
y:>>> x = np.ma.array([0., 1., 2., 3., 4.]) >>> y = np.ma.array([1., 3., 5., 7., 999.], mask=[0, 0, 0, 0, 1]) >>> np.ma.polyfit(x, y, 1) array([2., 1.])
Masking a value in
xalso excludes the correspondingypoint:>>> x = np.ma.array([0., 1., 999., 3., 4.], mask=[0, 0, 1, 0, 0]) >>> y = np.ma.array([1., 3., 5., 7., 9.]) >>> np.ma.polyfit(x, y, 1) array([2., 1.])
Without masking, an outlier distorts the fit significantly:
>>> np.polyfit([0., 1., 2., 3., 4.], [1., 3., 5., 7., 999.], 1) array([ 200., -197.])