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. It’s used to print debug info for developers. Details: Name. Default: None.


The correlation coefficient matrix of the variables.


>>> import paddle
>>> paddle.seed(2023)

>>> xt = paddle.rand((3,4))
>>> print(paddle.linalg.corrcoef(xt))
Tensor(shape=[3, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
[[ 0.99999988, -0.47689581, -0.89559376],
 [-0.47689593,  1.        ,  0.16345492],
 [-0.89559382,  0.16345496,  1.        ]])