Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.cumulative_trapezoid function

PyTorch torch.cumulative_trapezoid function


PyTorch torch reference manual PyTorch torch reference manual

torch.cumulative_trapezoid is a PyTorch function for computing the cumulative trapezoidal integral of a function. It uses the trapezoidal rule to compute the cumulative integral of the function at given points.

Function definition

torch.cumulative_trapezoid(y, x=None, dx=1.0, dim=-1)

Parameters:

Return Value:


Usage examples

Example

import

torch

Create function values

y

=

torch.

tensor

(

[

1.0

,

2.0

,

3.0

,

4.0

,

5.0

]

)

Cumulative trapezoidal integration

result

=

torch.

cumulative_trapezoid

(

y

)

print

(

"Function values y:"

,

y

)

print

(

"Cumulative integration result:"

,

result

)

The output is:

函数值 y: tensor([1., 2., 3., 4., 5.])

累积积分结果: tensor([0.0000, 1.5000, 3.5000, 6.0000, 9.0000])

Example - Specifying x coordinates

import

torch

y

=

torch.

tensor

(

[

1.0

,

2.0

,

3.0

,

4.0

,

5.0

]

)

x

=

torch.

tensor

(

[

0.0

,

0.5

,

1.0

,

1.5

,

2.0

]

)

result

=

torch.

cumulative_trapezoid

(

y

,

x

)

print

(

"Cumulative integration result:"

,

result

)


PyTorch torch reference manual PyTorch torch reference manual