paddle.linalg. corrcoef ( x, rowvar=True, name=None ) [source]

A correlation coefficient matrix indicate the correlation of each pair variables in the input matrix. For example, for an N-dimensional samples X=[x1,x2,…xN]T, then the correlation coefficient matrix element Rij is the correlation of xi and xj. The element Rii is the covariance of xi itself.

The relationship between the correlation coefficient matrix R and the covariance matrix C, is

\[R_{ij} = \frac{ C_{ij} } { \sqrt{ C_{ii} * C_{jj} } }\]

The values of R are between -1 and 1.

  • x (Tensor) – A N-D(N<=2) Tensor containing multiple variables and observations. By default, each row of x represents a variable. Also see rowvar below.

  • rowvar (Bool, optional) – If rowvar is True (default), then each row represents a variable, with observations in the columns. Default: True.

  • name (str, optional) – Name of the output. Default is None. It’s used to print debug info for developers. Details: Name.


The correlation coefficient matrix of the variables.


import paddle

xt = paddle.rand((3,4))

# Tensor(shape=[3, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
# [[ 1.        , -0.73702252,  0.66228950],
# [-0.73702258,  1.        , -0.77104872],
# [ 0.66228974, -0.77104825,  1.        ]])