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

Function corrcoef

numpy/lib/_function_base_impl.py:2911–3046  ·  view source on GitHub ↗

Return Pearson product-moment correlation coefficients. Please refer to the documentation for `cov` for more detail. The relationship between the correlation coefficient matrix, `R`, and the covariance matrix, `C`, is .. math:: R_{ij} = \\frac{ C_{ij} } { \\sqrt{ C_{ii} C_{jj

(x, y=None, rowvar=True, *,
             dtype=None)

Source from the content-addressed store, hash-verified

2909
2910@array_function_dispatch(_corrcoef_dispatcher)
2911def corrcoef(x, y=None, rowvar=True, *,
2912 dtype=None):
2913 """
2914 Return Pearson product-moment correlation coefficients.
2915
2916 Please refer to the documentation for `cov` for more detail. The
2917 relationship between the correlation coefficient matrix, `R`, and the
2918 covariance matrix, `C`, is
2919
2920 .. math:: R_{ij} = \\frac{ C_{ij} } { \\sqrt{ C_{ii} C_{jj} } }
2921
2922 The values of `R` are between -1 and 1, inclusive.
2923
2924 Parameters
2925 ----------
2926 x : array_like
2927 A 1-D or 2-D array containing multiple variables and observations.
2928 Each row of `x` represents a variable, and each column a single
2929 observation of all those variables. Also see `rowvar` below.
2930 y : array_like, optional
2931 An additional set of variables and observations. `y` has the same
2932 shape as `x`.
2933 rowvar : bool, optional
2934 If `rowvar` is True (default), then each row represents a
2935 variable, with observations in the columns. Otherwise, the relationship
2936 is transposed: each column represents a variable, while the rows
2937 contain observations.
2938
2939 dtype : data-type, optional
2940 Data-type of the result. By default, the return data-type will have
2941 at least `numpy.float64` precision.
2942
2943 .. versionadded:: 1.20
2944
2945 Returns
2946 -------
2947 R : ndarray
2948 The correlation coefficient matrix of the variables.
2949
2950 See Also
2951 --------
2952 cov : Covariance matrix
2953
2954 Notes
2955 -----
2956 Due to floating point rounding the resulting array may not be Hermitian,
2957 the diagonal elements may not be 1, and the elements may not satisfy the
2958 inequality abs(a) <= 1. The real and imaginary parts are clipped to the
2959 interval [-1, 1] in an attempt to improve on that situation but is not
2960 much help in the complex case.
2961
2962 Examples
2963 --------
2964 >>> import numpy as np
2965
2966 In this example we generate two random arrays, ``xarr`` and ``yarr``, and
2967 compute the row-wise and column-wise Pearson correlation coefficients,
2968 ``R``. Since ``rowvar`` is true by default, we first find the row-wise

Callers 5

test_simpleMethod · 0.90
test_complexMethod · 0.90
test_emptyMethod · 0.90
test_extremeMethod · 0.90
test_corrcoef_dtypeMethod · 0.90

Calls 4

diagFunction · 0.90
sqrtFunction · 0.85
clipMethod · 0.80
covFunction · 0.70

Tested by 5

test_simpleMethod · 0.72
test_complexMethod · 0.72
test_emptyMethod · 0.72
test_extremeMethod · 0.72
test_corrcoef_dtypeMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…