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

Function cumulative_trapezoid

xarray/core/duck_array_ops.py:231–247  ·  view source on GitHub ↗
(y, x, axis)

Source from the content-addressed store, hash-verified

229
230
231def cumulative_trapezoid(y, x, axis):
232 if axis < 0:
233 axis = y.ndim + axis
234 x_sl1 = (slice(1, None),) + (None,) * (y.ndim - axis - 1)
235 x_sl2 = (slice(None, -1),) + (None,) * (y.ndim - axis - 1)
236 slice1 = (slice(None),) * axis + (slice(1, None),)
237 slice2 = (slice(None),) * axis + (slice(None, -1),)
238 dx = x[x_sl1] - x[x_sl2]
239 integrand = dx * 0.5 * (y[tuple(slice1)] + y[tuple(slice2)])
240
241 # Pad so that 'axis' has same length in result as it did in y
242 pads = [(1, 0) if i == axis else (0, 0) for i in range(y.ndim)]
243
244 xp = get_array_namespace(y, x)
245 integrand = xp.pad(integrand, pads, mode="constant", constant_values=0.0)
246
247 return cumsum(integrand, axis=axis, skipna=False)
248
249
250def full_like(a, fill_value, **kwargs):

Callers 1

Calls 3

get_array_namespaceFunction · 0.90
cumsumFunction · 0.85
padMethod · 0.45

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…