Estimate the covariance matrix. Except for the handling of missing data this function does the same as `numpy.cov`. For more details and examples, see `numpy.cov`. By default, masked values are recognized as such. If `x` and `y` have the same shape, a common mask is allocated:
(x, y=None, rowvar=True, bias=False, allow_masked=True, ddof=None)
| 1442 | |
| 1443 | |
| 1444 | def cov(x, y=None, rowvar=True, bias=False, allow_masked=True, ddof=None): |
| 1445 | """ |
| 1446 | Estimate the covariance matrix. |
| 1447 | |
| 1448 | Except for the handling of missing data this function does the same as |
| 1449 | `numpy.cov`. For more details and examples, see `numpy.cov`. |
| 1450 | |
| 1451 | By default, masked values are recognized as such. If `x` and `y` have the |
| 1452 | same shape, a common mask is allocated: if ``x[i,j]`` is masked, then |
| 1453 | ``y[i,j]`` will also be masked. |
| 1454 | Setting `allow_masked` to False will raise an exception if values are |
| 1455 | missing in either of the input arrays. |
| 1456 | |
| 1457 | Parameters |
| 1458 | ---------- |
| 1459 | x : array_like |
| 1460 | A 1-D or 2-D array containing multiple variables and observations. |
| 1461 | Each row of `x` represents a variable, and each column a single |
| 1462 | observation of all those variables. Also see `rowvar` below. |
| 1463 | y : array_like, optional |
| 1464 | An additional set of variables and observations. `y` has the same |
| 1465 | shape as `x`. |
| 1466 | rowvar : bool, optional |
| 1467 | If `rowvar` is True (default), then each row represents a |
| 1468 | variable, with observations in the columns. Otherwise, the relationship |
| 1469 | is transposed: each column represents a variable, while the rows |
| 1470 | contain observations. |
| 1471 | bias : bool, optional |
| 1472 | Default normalization (False) is by ``(N-1)``, where ``N`` is the |
| 1473 | number of observations given (unbiased estimate). If `bias` is True, |
| 1474 | then normalization is by ``N``. This keyword can be overridden by |
| 1475 | the keyword ``ddof`` in numpy versions >= 1.5. |
| 1476 | allow_masked : bool, optional |
| 1477 | If True, masked values are propagated pair-wise: if a value is masked |
| 1478 | in `x`, the corresponding value is masked in `y`. |
| 1479 | If False, raises a `ValueError` exception when some values are missing. |
| 1480 | ddof : {None, int}, optional |
| 1481 | If not ``None`` normalization is by ``(N - ddof)``, where ``N`` is |
| 1482 | the number of observations; this overrides the value implied by |
| 1483 | ``bias``. The default value is ``None``. |
| 1484 | |
| 1485 | .. versionadded:: 1.5 |
| 1486 | |
| 1487 | Raises |
| 1488 | ------ |
| 1489 | ValueError |
| 1490 | Raised if some values are missing and `allow_masked` is False. |
| 1491 | |
| 1492 | See Also |
| 1493 | -------- |
| 1494 | numpy.cov |
| 1495 | |
| 1496 | """ |
| 1497 | # Check inputs |
| 1498 | if ddof is not None and ddof != int(ddof): |
| 1499 | raise ValueError("ddof must be an integer") |
| 1500 | # Set up ddof |
| 1501 | if ddof is None: |