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)
| 2529 | |
| 2530 | @array_function_dispatch(_cov_dispatcher) |
| 2531 | def 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 |