(y, x, axis)
| 229 | |
| 230 | |
| 231 | def 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 | |
| 250 | def full_like(a, fill_value, **kwargs): |
searching dependent graphs…