MCPcopy
hub / github.com/pydata/xarray / corr

Function corr

xarray/computation/computation.py:152–252  ·  view source on GitHub ↗

Compute the Pearson correlation coefficient 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

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

Source from the content-addressed store, hash-verified

150
151
152def corr(
153 da_a: T_DataArray,
154 da_b: T_DataArray,
155 dim: Dims = None,
156 weights: T_DataArray | None = None,
157) -> T_DataArray:
158 """
159 Compute the Pearson correlation coefficient between
160 two DataArray objects along a shared dimension.
161
162 Parameters
163 ----------
164 da_a : DataArray
165 Array to compute.
166 da_b : DataArray
167 Array to compute.
168 dim : str, iterable of hashable, "..." or None, optional
169 The dimension along which the correlation will be computed
170 weights : DataArray, optional
171 Array of weights.
172
173 Returns
174 -------
175 correlation: DataArray
176
177 See Also
178 --------
179 pandas.Series.corr : corresponding pandas function
180 xarray.cov : underlying covariance function
181
182 Examples
183 --------
184 >>> from xarray import DataArray
185 >>> da_a = DataArray(
186 ... np.array([[1, 2, 3], [0.1, 0.2, 0.3], [3.2, 0.6, 1.8]]),
187 ... dims=("space", "time"),
188 ... coords=[
189 ... ("space", ["IA", "IL", "IN"]),
190 ... ("time", pd.date_range("2000-01-01", freq="1D", periods=3)),
191 ... ],
192 ... )
193 >>> da_a
194 <xarray.DataArray (space: 3, time: 3)> Size: 72B
195 array([[1. , 2. , 3. ],
196 [0.1, 0.2, 0.3],
197 [3.2, 0.6, 1.8]])
198 Coordinates:
199 * space (space) <U2 24B 'IA' 'IL' 'IN'
200 * time (time) datetime64[us] 24B 2000-01-01 2000-01-02 2000-01-03
201 >>> da_b = DataArray(
202 ... np.array([[0.2, 0.4, 0.6], [15, 10, 5], [3.2, 0.6, 1.8]]),
203 ... dims=("space", "time"),
204 ... coords=[
205 ... ("space", ["IA", "IL", "IN"]),
206 ... ("time", pd.date_range("2000-01-01", freq="1D", periods=3)),
207 ... ],
208 ... )
209 >>> da_b

Callers

nothing calls this directly

Calls 2

typeFunction · 0.85
_cov_corrFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…