MCPcopy Index your code
hub / github.com/pydata/xarray / cov

Function cov

xarray/computation/computation.py:46–149  ·  view source on GitHub ↗

Compute covariance between two DataArray objects along a shared dimension. Parameters ---------- da_a : DataArray Array to compute. da_b : DataArray Array to compute. dim : str, iterable of hashable, "..." or None, optional The dimension along which

(
    da_a: T_DataArray,
    da_b: T_DataArray,
    dim: Dims = None,
    ddof: int = 1,
    weights: T_DataArray | None = None,
)

Source from the content-addressed store, hash-verified

44
45
46def cov(
47 da_a: T_DataArray,
48 da_b: T_DataArray,
49 dim: Dims = None,
50 ddof: int = 1,
51 weights: T_DataArray | None = None,
52) -> T_DataArray:
53 """
54 Compute covariance between two DataArray objects along a shared dimension.
55
56 Parameters
57 ----------
58 da_a : DataArray
59 Array to compute.
60 da_b : DataArray
61 Array to compute.
62 dim : str, iterable of hashable, "..." or None, optional
63 The dimension along which the covariance will be computed
64 ddof : int, default: 1
65 If ddof=1, covariance is normalized by N-1, giving an unbiased estimate,
66 else normalization is by N.
67 weights : DataArray, optional
68 Array of weights.
69
70 Returns
71 -------
72 covariance : DataArray
73
74 See Also
75 --------
76 pandas.Series.cov : corresponding pandas function
77 xarray.corr : respective function to calculate correlation
78
79 Examples
80 --------
81 >>> from xarray import DataArray
82 >>> da_a = DataArray(
83 ... np.array([[1, 2, 3], [0.1, 0.2, 0.3], [3.2, 0.6, 1.8]]),
84 ... dims=("space", "time"),
85 ... coords=[
86 ... ("space", ["IA", "IL", "IN"]),
87 ... ("time", pd.date_range("2000-01-01", freq="1D", periods=3)),
88 ... ],
89 ... )
90 >>> da_a
91 <xarray.DataArray (space: 3, time: 3)> Size: 72B
92 array([[1. , 2. , 3. ],
93 [0.1, 0.2, 0.3],
94 [3.2, 0.6, 1.8]])
95 Coordinates:
96 * space (space) <U2 24B 'IA' 'IL' 'IN'
97 * time (time) datetime64[us] 24B 2000-01-01 2000-01-02 2000-01-03
98 >>> da_b = DataArray(
99 ... np.array([[0.2, 0.4, 0.6], [15, 10, 5], [3.2, 0.6, 1.8]]),
100 ... dims=("space", "time"),
101 ... coords=[
102 ... ("space", ["IA", "IL", "IN"]),
103 ... ("time", pd.date_range("2000-01-01", freq="1D", periods=3)),

Callers

nothing calls this directly

Calls 2

typeFunction · 0.85
_cov_corrFunction · 0.85

Tested by

no test coverage detected