Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Please select the type of question

Problem description

Describe the bug so that we can quickly locate the problem.

mindspore.ops.trapz

mindspore.ops.trapz(y, x=None, *, dx=1.0, dim=- 1)[source]

Integrates y(x) along given dim using trapezoidal rule. By default x-dim distances between points will be 1.0, alternatively they can be provided with x array or with dx scalar.

y(x)dx
Parameters
  • y (Tensor) – Input tensor to integrate.

  • x (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. Default: None . If x is not None, after subtracting 1 from the axis specified by dim, the shape of x should be same as y or can broadcast to y.

Keyword Arguments
  • dx (float, optional) – The spacing between sample points when x is None. If x is specified, dx does not take effect. Default: 1.0 .

  • dim (int, optional) – The dim along which to integrate. Default: -1 .

Returns

Tensor of float, definite integral as approximated by trapezoidal rule. If y is a one-dimensional array, the result is a floating-point number. If y is an n-dimensional array, the result is an N-1 dimensional array.

Raises
  • RuntimeError – If dim of x is 1, and x.shape[0] is not equal to y.shape[dim].

  • ValueError – If dim is out of range of [y.ndim,y.ndim).

  • TypeError – If y is not a Tensor.

  • TypeError – If x is not None and is not a Tensor.

  • TypeError – If dx is not a float number.

  • TypeError – If dim is not a Integer.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> y = Tensor(np.array([[1., 1., 1.], [1., 1., 1.], [1., 1., 1.]]).astype(np.float32))
>>> x = Tensor(np.array([[1, 2, 3], [1, 3, 5], [1, 4, 7]]).astype(np.float32))
>>> output = ops.trapz(y, x)
>>> print(output)
[2. 4. 6.]