MCPcopy Create free account
hub / github.com/numpy/numpy / polyfit

Function polyfit

numpy/ma/extras.py:2099–2131  ·  view source on GitHub ↗

Any masked values in x is propagated in y, and vice-versa.

(x, y, deg, rcond=None, full=False, w=None, cov=False)

Source from the content-addressed store, hash-verified

2097
2098
2099def polyfit(x, y, deg, rcond=None, full=False, w=None, cov=False):
2100 """
2101 Any masked values in x is propagated in y, and vice-versa.
2102
2103 """
2104 x = asarray(x)
2105 y = asarray(y)
2106
2107 m = getmask(x)
2108 if y.ndim == 1:
2109 m = mask_or(m, getmask(y))
2110 elif y.ndim == 2:
2111 my = getmask(mask_rows(y))
2112 if my is not nomask:
2113 m = mask_or(m, my[:, 0])
2114 else:
2115 raise TypeError("Expected a 1D or 2D array for y!")
2116
2117 if w is not None:
2118 w = asarray(w)
2119 if w.ndim != 1:
2120 raise TypeError("expected a 1-d array for weights")
2121 if w.shape[0] != y.shape[0]:
2122 raise TypeError("expected w and y to have the same length")
2123 m = mask_or(m, getmask(w))
2124
2125 if m is not nomask:
2126 not_m = ~m
2127 if w is not None:
2128 w = w[not_m]
2129 return np.polyfit(x[not_m], y[not_m], deg, rcond, full, w, cov)
2130 else:
2131 return np.polyfit(x, y, deg, rcond, full, w, cov)
2132
2133polyfit.__doc__ = ma.doc_note(np.polyfit.__doc__, polyfit.__doc__)

Callers 3

test_polyfitMethod · 0.90
_mac_os_checkFunction · 0.50

Calls 4

getmaskFunction · 0.85
mask_orFunction · 0.85
mask_rowsFunction · 0.85
asarrayFunction · 0.70

Tested by 2

test_polyfitMethod · 0.72