diff options
Diffstat (limited to 'numpy/ma/extras.py')
-rw-r--r-- | numpy/ma/extras.py | 68 |
1 files changed, 31 insertions, 37 deletions
diff --git a/numpy/ma/extras.py b/numpy/ma/extras.py index b6082180a..d389099ae 100644 --- a/numpy/ma/extras.py +++ b/numpy/ma/extras.py @@ -48,7 +48,6 @@ import numpy as np from numpy import ndarray, array as nxarray import numpy.core.umath as umath from numpy.lib.index_tricks import AxisConcatenator -from numpy.linalg import lstsq #............................................................................... @@ -730,6 +729,10 @@ def compress_rowcols(x, axis=None): Parameters ---------- + x : array_like, MaskedArray + The array to operate on. If not a MaskedArray instance (or if no array + elements are masked), `x` is interpreted as a MaskedArray with + `mask` set to `nomask`. Must be a 2D array. axis : int, optional Axis along which to perform the operation. Default is None. @@ -1044,13 +1047,7 @@ def dot(a, b, strict=False): if strict and (a.ndim == 2) and (b.ndim == 2): a = mask_rows(a) b = mask_cols(b) - # - d = np.dot(filled(a, 0), filled(b, 0)) - # - am = (~getmaskarray(a)) - bm = (~getmaskarray(b)) - m = ~np.dot(am, bm) - return masked_array(d, mask=m) + return a.dot(b) #####-------------------------------------------------------------------------- #---- --- arraysetops --- @@ -1373,9 +1370,10 @@ def cov(x, y=None, rowvar=True, bias=False, allow_masked=True, ddof=None): return result -def corrcoef(x, y=None, rowvar=True, bias=False, allow_masked=True, ddof=None): +def corrcoef(x, y=None, rowvar=True, bias=np._NoValue, allow_masked=True, + ddof=np._NoValue): """ - Return correlation coefficients of the input array. + Return Pearson product-moment correlation coefficients. Except for the handling of missing data this function does the same as `numpy.corrcoef`. For more details and examples, see `numpy.corrcoef`. @@ -1394,45 +1392,41 @@ def corrcoef(x, y=None, rowvar=True, bias=False, allow_masked=True, ddof=None): variable, with observations in the columns. Otherwise, the relationship is transposed: each column represents a variable, while the rows contain observations. - bias : bool, optional - Default normalization (False) is by ``(N-1)``, where ``N`` is the - number of observations given (unbiased estimate). If `bias` is 1, - then normalization is by ``N``. This keyword can be overridden by - the keyword ``ddof`` in numpy versions >= 1.5. + bias : _NoValue, optional + .. deprecated:: 1.10.0 + Has no affect, do not use. allow_masked : bool, optional If True, masked values are propagated pair-wise: if a value is masked in `x`, the corresponding value is masked in `y`. - If False, raises an exception. - ddof : {None, int}, optional - .. versionadded:: 1.5 - If not ``None`` normalization is by ``(N - ddof)``, where ``N`` is - the number of observations; this overrides the value implied by - ``bias``. The default value is ``None``. + If False, raises an exception. Because `bias` is deprecated, this + argument needs to be treated as keyword only to avoid a warning. + ddof : _NoValue, optional + .. deprecated:: 1.10.0 + Has no affect, do not use. See Also -------- numpy.corrcoef : Equivalent function in top-level NumPy module. cov : Estimate the covariance matrix. - """ - # Check inputs - if ddof is not None and ddof != int(ddof): - raise ValueError("ddof must be an integer") - # Set up ddof - if ddof is None: - if bias: - ddof = 0 - else: - ddof = 1 - + Notes + ----- + This function accepts but discards arguments `bias` and `ddof`. This is + for backwards compatibility with previous versions of this function. These + arguments had no effect on the return values of the function and can be + safely ignored in this and previous versions of numpy. + """ + msg = 'bias and ddof have no affect and are deprecated' + if bias is not np._NoValue or ddof is not np._NoValue: + warnings.warn(msg, DeprecationWarning) # Get the data (x, xnotmask, rowvar) = _covhelper(x, y, rowvar, allow_masked) # Compute the covariance matrix if not rowvar: - fact = np.dot(xnotmask.T, xnotmask) * 1. - ddof + fact = np.dot(xnotmask.T, xnotmask) * 1. c = (dot(x.T, x.conj(), strict=False) / fact).squeeze() else: - fact = np.dot(xnotmask, xnotmask.T) * 1. - ddof + fact = np.dot(xnotmask, xnotmask.T) * 1. c = (dot(x, x.T.conj(), strict=False) / fact).squeeze() # Check whether we have a scalar try: @@ -1448,13 +1442,13 @@ def corrcoef(x, y=None, rowvar=True, bias=False, allow_masked=True, ddof=None): if rowvar: for i in range(n - 1): for j in range(i + 1, n): - _x = mask_cols(vstack((x[i], x[j]))).var(axis=1, ddof=ddof) + _x = mask_cols(vstack((x[i], x[j]))).var(axis=1) _denom[i, j] = _denom[j, i] = ma.sqrt(ma.multiply.reduce(_x)) else: for i in range(n - 1): for j in range(i + 1, n): _x = mask_cols( - vstack((x[:, i], x[:, j]))).var(axis=1, ddof=ddof) + vstack((x[:, i], x[:, j]))).var(axis=1) _denom[i, j] = _denom[j, i] = ma.sqrt(ma.multiply.reduce(_x)) return c / _denom @@ -1561,7 +1555,7 @@ def flatnotmasked_edges(a): Parameters ---------- - arr : array_like + a : array_like Input 1-D `MaskedArray` Returns |