mindspore.numpy.trapz
- mindspore.numpy.trapz(y, x=None, dx=1.0, axis=- 1)[源代码]
Integrates along the given axis using the composite trapezoidal rule.
Integrates y (x) along given axis.
- Parameters
y (Tensor) – Input array to integrate.
x (Union[int, float, bool, list, tuple, Tensor], optional) – The sample points corresponding to the y values. If x is None, the sample points are assumed to be evenly spaced dx apart. The default is None.
dx (scalar, optional) – The spacing between sample points when x is None. The default is 1.0.
axis (int, optional) – The axis along which to integrate. Defaults to -1.
- Returns
Tensor of float, definite integral as approximated by trapezoidal rule.
- Raises
ValueError – If axis is out of range of
[-y.ndim, y.ndim)
.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore.numpy as np >>> a = np.arange(6).reshape(2, 3) >>> output = np.trapz(a, x=[-2, 1, 2], axis=1) >>> print(output) [ 3. 15.] >>> output = np.trapz(a, dx=3, axis=0) >>> print(output) [ 4.5 7.5 10.5]