torch.corrcoef
- torch.corrcoef(input) → Tensor
Estimates the Pearson product-moment correlation coefficient matrix of the variables given by the
inputmatrix, where rows are the variables and columns are the observations.
Estimates the Pearson product-moment correlation coefficient matrix of the variables given by the input matrix,
where rows are the variables and columns are the observations.
The correlation coefficient matrix R is computed using the covariance matrix C as given by
input (Tensor) – A 2D matrix containing multiple variables and observations, or a Scalar or 1D vector representing a single variable.
(Tensor) The correlation coefficient matrix of the variables.
Example:
>>> x = torch.tensor([[0, 1, 2], [2, 1, 0]])
>>> torch.corrcoef(x)
tensor([[ 1., -1.],
[-1., 1.]])
>>> x = torch.randn(2, 4)
>>> x
tensor([[-0.2678, -0.0908, -0.3766, 0.2780],
[-0.5812, 0.1535, 0.2387, 0.2350]])
>>> torch.corrcoef(x)
tensor([[1.0000, 0.3582],
[0.3582, 1.0000]])
>>> torch.corrcoef(x[0])
tensor(1.)