本文簡要介紹python語言中 torch.cumulative_trapezoid
的用法。
用法:
torch.cumulative_trapezoid(y, x=None, *, dx=None, dim=- 1) → Tensor
沿著
dim
累積計算 trapezoidal rule 。默認情況下,元素之間的間距假定為 1,但dx
可用於指定不同的常量間距,並且x
可用於指定沿dim
的任意間距。更多詳情,請閱讀
torch.trapezoid()
。torch.trapezoid()
與此函數之間的區別在於,torch.trapezoid()
為每個積分返回一個值,而此函數為積分中的每個間距返回一個累積值。這類似於.sum
如何返回一個值,而.cumsum
返回一個累積和。例子:
>>> # Cumulatively computes the trapezoidal rule in 1D, spacing is implicitly 1. >>> y = torch.tensor([1, 5, 10]) >>> torch.cumulative_trapezoid(y) tensor([3., 10.5]) >>> # Computes the same trapezoidal rule directly up to each element to verify >>> (1 + 5) / 2 3.0 >>> (1 + 10 + 10) / 2 10.5 >>> # Cumulatively computes the trapezoidal rule in 1D with constant spacing of 2 >>> # NOTE: the result is the same as before, but multiplied by 2 >>> torch.cumulative_trapezoid(y, dx=2) tensor([6., 21.]) >>> # Cumulatively computes the trapezoidal rule in 1D with arbitrary spacing >>> x = torch.tensor([1, 3, 6]) >>> torch.cumulative_trapezoid(y, x) tensor([6., 28.5]) >>> # Computes the same trapezoidal rule directly up to each element to verify >>> ((3 - 1) * (1 + 5)) / 2 6.0 >>> ((3 - 1) * (1 + 5) + (6 - 3) * (5 + 10)) / 2 28.5 >>> # Cumulatively computes the trapezoidal rule for each row of a 3x3 matrix >>> y = torch.arange(9).reshape(3, 3) tensor([[0, 1, 2], [3, 4, 5], [6, 7, 8]]) >>> torch.cumulative_trapezoid(y) tensor([[ 0.5, 2.], [ 3.5, 8.], [ 6.5, 14.]]) >>> # Cumulatively computes the trapezoidal rule for each column of the matrix >>> torch.cumulative_trapezoid(y, dim=0) tensor([[ 1.5, 2.5, 3.5], [ 6.0, 8.0, 10.0]]) >>> # Cumulatively computes the trapezoidal rule for each row of a 3x3 ones matrix >>> # with the same arbitrary spacing >>> y = torch.ones(3, 3) >>> x = torch.tensor([1, 3, 6]) >>> torch.cumulative_trapezoid(y, x) tensor([[2., 5.], [2., 5.], [2., 5.]]) >>> # Cumulatively computes the trapezoidal rule for each row of a 3x3 ones matrix >>> # with different arbitrary spacing per row >>> y = torch.ones(3, 3) >>> x = torch.tensor([[1, 2, 3], [1, 3, 5], [1, 4, 7]]) >>> torch.cumulative_trapezoid(y, x) tensor([[1., 2.], [2., 4.], [3., 6.]])
參數:
關鍵字參數:
相關用法
- Python PyTorch cumprod用法及代碼示例
- Python PyTorch cummax用法及代碼示例
- Python PyTorch cumsum用法及代碼示例
- Python PyTorch cummin用法及代碼示例
- Python PyTorch custom_from_mask用法及代碼示例
- Python PyTorch custom_replace用法及代碼示例
- Python PyTorch cholesky用法及代碼示例
- Python PyTorch column_stack用法及代碼示例
- Python PyTorch calculate_gain用法及代碼示例
- Python PyTorch cov用法及代碼示例
- Python PyTorch cos用法及代碼示例
- Python PyTorch compute_deltas用法及代碼示例
- Python PyTorch conv_transpose3d用法及代碼示例
- Python PyTorch combinations用法及代碼示例
- Python PyTorch conv2d用法及代碼示例
- Python PyTorch collect_all用法及代碼示例
- Python PyTorch chunk用法及代碼示例
- Python PyTorch convert用法及代碼示例
- Python PyTorch conv1d用法及代碼示例
- Python PyTorch chain_matmul用法及代碼示例
- Python PyTorch cat用法及代碼示例
- Python PyTorch constant_用法及代碼示例
- Python PyTorch context用法及代碼示例
- Python PyTorch count_nonzero用法及代碼示例
- Python PyTorch cdist用法及代碼示例
注:本文由純淨天空篩選整理自pytorch.org大神的英文原創作品 torch.cumulative_trapezoid。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。