paddle.linalg. cov ( x, rowvar=True, ddof=True, fweights=None, aweights=None, name=None ) [source]

Estimate the covariance matrix of the input variables, given data and weights.

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

  • 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

  • ddof (Bool, optional) – If ddof=True will return the unbiased estimate, and ddof=False will return the simple average. Default: True

  • fweights (Tensor, optional) – 1-D Tensor of integer frequency weights; The number of times each observation vector should be repeated. Default: None

  • aweights (Tensor, optional) – 1-D Tensor of observation vector weights. How important of the observation vector, larger data means this element is more important. Default: None

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


The covariance matrix Tensor of the variables.

Return type



import paddle

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

Tensor(shape=[3, 3], dtype=float64, place=CUDAPlace(0), stop_gradient=True,
    [[0.07918842, 0.06127326, 0.01493049],
        [0.06127326, 0.06166256, 0.00302668],
        [0.01493049, 0.00302668, 0.01632146]])