bundles / scipy latest / scipy / _lib / array_api_extra / _delegation / cov
function
scipy._lib.array_api_extra._delegation:cov
Signature
def cov ( m : Array , / , xp : ModuleType | None = None ) → Array Summary
Estimate a covariance matrix (or a stack of covariance matrices).
Extended Summary
Covariance indicates the level to which two variables vary together. If we examine N-dimensional samples, , each with M observations, then element of the covariance matrix is the covariance of and . The element is the variance of .
With the exception of supporting batch input, this provides a subset of the functionality of numpy.cov.
Parameters
m: arrayAn array of shape
(..., N, M)whose innermost two dimensions contain M observations of N variables. That is, each row ofmrepresents a variable, and each column a single observation of all those variables.xp: array_namespace, optionalThe standard-compatible namespace for
m. Default: infer.
Returns
: arrayAn array having shape (..., N, N) whose innermost two dimensions represent the covariance matrix of the variables.
Examples
import array_api_strict as xp import array_api_extra as xpx⚠
x = xp.asarray([[0, 2], [1, 1], [2, 0]]).T x⚠
xpx.cov(x, xp=xp)
⚠x = xp.asarray([-2.1, -1, 4.3]) y = xp.asarray([3, 1.1, 0.12]) X = xp.stack((x, y), axis=0) xpx.cov(X, xp=xp)⚠
xpx.cov(x, xp=xp)
⚠xpx.cov(y, xp=xp)
⚠stack = xp.stack((X, 2*X)) xpx.cov(stack)⚠
Aliases
-
scipy.differentiate.xpx.cov