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)
| 2686 | |
| 2687 | @array_function_dispatch(_cov_dispatcher) |
| 2688 | def cov(m, y=None, rowvar=True, bias=False, ddof=None, fweights=None, |
| 2689 | aweights=None, *, dtype=None): |
| 2690 | """ |
| 2691 | Estimate a covariance matrix, given data and weights. |
| 2692 | |
| 2693 | Covariance indicates the level to which two variables vary together. |
| 2694 | If we examine N-dimensional samples, :math:`X = [x_1, x_2, ..., x_N]^T`, |
| 2695 | then the covariance matrix element :math:`C_{ij}` is the covariance of |
| 2696 | :math:`x_i` and :math:`x_j`. The element :math:`C_{ii}` is the variance |
| 2697 | of :math:`x_i`. |
| 2698 | |
| 2699 | See the notes for an outline of the algorithm. |
| 2700 | |
| 2701 | Parameters |
| 2702 | ---------- |
| 2703 | m : array_like |
| 2704 | A 1-D or 2-D array containing multiple variables and observations. |
| 2705 | Each row of `m` represents a variable, and each column a single |
| 2706 | observation of all those variables. Also see `rowvar` below. |
| 2707 | y : array_like, optional |
| 2708 | An additional set of variables and observations. `y` has the same form |
| 2709 | as that of `m`. |
| 2710 | rowvar : bool, optional |
| 2711 | If `rowvar` is True (default), then each row represents a |
| 2712 | variable, with observations in the columns. Otherwise, the relationship |
| 2713 | is transposed: each column represents a variable, while the rows |
| 2714 | contain observations. |
| 2715 | bias : bool, optional |
| 2716 | Default normalization (False) is by ``(N - 1)``, where ``N`` is the |
| 2717 | number of observations given (unbiased estimate). If `bias` is True, |
| 2718 | then normalization is by ``N``. These values can be overridden by using |
| 2719 | the keyword ``ddof`` in numpy versions >= 1.5. |
| 2720 | ddof : int, optional |
| 2721 | If not ``None`` the default value implied by `bias` is overridden. |
| 2722 | Note that ``ddof=1`` will return the unbiased estimate, even if both |
| 2723 | `fweights` and `aweights` are specified, and ``ddof=0`` will return |
| 2724 | the simple average. See the notes for the details. The default value |
| 2725 | is ``None``. |
| 2726 | fweights : array_like, int, optional |
| 2727 | 1-D array of integer frequency weights; the number of times each |
| 2728 | observation vector should be repeated. |
| 2729 | aweights : array_like, optional |
| 2730 | 1-D array of observation vector weights. These relative weights are |
| 2731 | typically large for observations considered "important" and smaller for |
| 2732 | observations considered less "important". If ``ddof=0`` the array of |
| 2733 | weights can be used to assign probabilities to observation vectors. |
| 2734 | dtype : data-type, optional |
| 2735 | Data-type of the result. By default, the return data-type will have |
| 2736 | at least `numpy.float64` precision. |
| 2737 | |
| 2738 | .. versionadded:: 1.20 |
| 2739 | |
| 2740 | Returns |
| 2741 | ------- |
| 2742 | out : ndarray |
| 2743 | The covariance matrix of the variables. |
| 2744 | |
| 2745 | See Also |