MCPcopy Index your code
hub / github.com/numpy/numpy / corrcoef

Function corrcoef

numpy/ma/extras.py:1675–1730  ·  view source on GitHub ↗

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`. Parameters ---------- x : array_like A 1-D or 2-D array containing

(x, y=None, rowvar=True, allow_masked=True,
             )

Source from the content-addressed store, hash-verified

1673
1674
1675def corrcoef(x, y=None, rowvar=True, allow_masked=True,
1676 ):
1677 """
1678 Return Pearson product-moment correlation coefficients.
1679
1680 Except for the handling of missing data this function does the same as
1681 `numpy.corrcoef`. For more details and examples, see `numpy.corrcoef`.
1682
1683 Parameters
1684 ----------
1685 x : array_like
1686 A 1-D or 2-D array containing multiple variables and observations.
1687 Each row of `x` represents a variable, and each column a single
1688 observation of all those variables. Also see `rowvar` below.
1689 y : array_like, optional
1690 An additional set of variables and observations. `y` has the same
1691 shape as `x`.
1692 rowvar : bool, optional
1693 If `rowvar` is True (default), then each row represents a
1694 variable, with observations in the columns. Otherwise, the relationship
1695 is transposed: each column represents a variable, while the rows
1696 contain observations.
1697 allow_masked : bool, optional
1698 If True, masked values are propagated pair-wise: if a value is masked
1699 in `x`, the corresponding value is masked in `y`.
1700 If False, raises an exception. Because `bias` is deprecated, this
1701 argument needs to be treated as keyword only to avoid a warning.
1702
1703 See Also
1704 --------
1705 numpy.corrcoef : Equivalent function in top-level NumPy module.
1706 cov : Estimate the covariance matrix.
1707
1708 Examples
1709 --------
1710 >>> import numpy as np
1711 >>> x = np.ma.array([[0, 1], [1, 1]], mask=[0, 1, 0, 1])
1712 >>> np.ma.corrcoef(x)
1713 masked_array(
1714 data=[[--, --],
1715 [--, --]],
1716 mask=[[ True, True],
1717 [ True, True]],
1718 fill_value=1e+20,
1719 dtype=float64)
1720
1721 """
1722 # Estimate the covariance matrix.
1723 corr = cov(x, y, rowvar, allow_masked=allow_masked)
1724 # The non-masked version returns a masked value for a scalar.
1725 try:
1726 std = ma.sqrt(ma.diagonal(corr))
1727 except ValueError:
1728 return ma.MaskedConstant()
1729 corr /= ma.multiply.outer(std, std)
1730 return corr
1731
1732#####--------------------------------------------------------------------------

Callers 4

test_1d_with_missingMethod · 0.90
test_2d_with_missingMethod · 0.90

Calls 2

covFunction · 0.70
outerMethod · 0.45

Tested by 4

test_1d_with_missingMethod · 0.72
test_2d_with_missingMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…