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

Function cov

numpy/lib/function_base.py:2531–2749  ·  view source on GitHub ↗

Estimate a covariance matrix, given data and weights. Covariance indicates the level to which two variables vary together. If we examine N-dimensional samples, :math:`X = [x_1, x_2, ... x_N]^T`, then the covariance matrix element :math:`C_{ij}` is the covariance of :math:`x_i`

(m, y=None, rowvar=True, bias=False, ddof=None, fweights=None,
        aweights=None, *, dtype=None)

Source from the content-addressed store, hash-verified

2529
2530@array_function_dispatch(_cov_dispatcher)
2531def cov(m, y=None, rowvar=True, bias=False, ddof=None, fweights=None,
2532 aweights=None, *, dtype=None):
2533 """
2534 Estimate a covariance matrix, given data and weights.
2535
2536 Covariance indicates the level to which two variables vary together.
2537 If we examine N-dimensional samples, :math:`X = [x_1, x_2, ... x_N]^T`,
2538 then the covariance matrix element :math:`C_{ij}` is the covariance of
2539 :math:`x_i` and :math:`x_j`. The element :math:`C_{ii}` is the variance
2540 of :math:`x_i`.
2541
2542 See the notes for an outline of the algorithm.
2543
2544 Parameters
2545 ----------
2546 m : array_like
2547 A 1-D or 2-D array containing multiple variables and observations.
2548 Each row of `m` represents a variable, and each column a single
2549 observation of all those variables. Also see `rowvar` below.
2550 y : array_like, optional
2551 An additional set of variables and observations. `y` has the same form
2552 as that of `m`.
2553 rowvar : bool, optional
2554 If `rowvar` is True (default), then each row represents a
2555 variable, with observations in the columns. Otherwise, the relationship
2556 is transposed: each column represents a variable, while the rows
2557 contain observations.
2558 bias : bool, optional
2559 Default normalization (False) is by ``(N - 1)``, where ``N`` is the
2560 number of observations given (unbiased estimate). If `bias` is True,
2561 then normalization is by ``N``. These values can be overridden by using
2562 the keyword ``ddof`` in numpy versions >= 1.5.
2563 ddof : int, optional
2564 If not ``None`` the default value implied by `bias` is overridden.
2565 Note that ``ddof=1`` will return the unbiased estimate, even if both
2566 `fweights` and `aweights` are specified, and ``ddof=0`` will return
2567 the simple average. See the notes for the details. The default value
2568 is ``None``.
2569
2570 .. versionadded:: 1.5
2571 fweights : array_like, int, optional
2572 1-D array of integer frequency weights; the number of times each
2573 observation vector should be repeated.
2574
2575 .. versionadded:: 1.10
2576 aweights : array_like, optional
2577 1-D array of observation vector weights. These relative weights are
2578 typically large for observations considered "important" and smaller for
2579 observations considered less "important". If ``ddof=0`` the array of
2580 weights can be used to assign probabilities to observation vectors.
2581
2582 .. versionadded:: 1.10
2583 dtype : data-type, optional
2584 Data-type of the result. By default, the return data-type will have
2585 at least `numpy.float64` precision.
2586
2587 .. versionadded:: 1.20
2588

Callers 12

test_basicMethod · 0.90
test_complexMethod · 0.90
test_xyMethod · 0.90
test_emptyMethod · 0.90
test_wrong_ddofMethod · 0.90
test_1D_rowvarMethod · 0.90
test_1D_varianceMethod · 0.90
test_fweightsMethod · 0.90
test_aweightsMethod · 0.90
test_cov_dtypeMethod · 0.90
corrcoefFunction · 0.70

Calls 9

anyFunction · 0.90
sumFunction · 0.90
reshapeMethod · 0.80
warnMethod · 0.80
averageFunction · 0.70
arrayFunction · 0.50
dotFunction · 0.50
allMethod · 0.45
squeezeMethod · 0.45

Tested by 11

test_basicMethod · 0.72
test_complexMethod · 0.72
test_xyMethod · 0.72
test_emptyMethod · 0.72
test_wrong_ddofMethod · 0.72
test_1D_rowvarMethod · 0.72
test_1D_varianceMethod · 0.72
test_fweightsMethod · 0.72
test_aweightsMethod · 0.72
test_cov_dtypeMethod · 0.72