Any masked values in x is propagated in y, and vice-versa.
(x, y, deg, rcond=None, full=False, w=None, cov=False)
| 2097 | |
| 2098 | |
| 2099 | def 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 | |
| 2133 | polyfit.__doc__ = ma.doc_note(np.polyfit.__doc__, polyfit.__doc__) |