PyTorch torch.cummin function
PyTorch torch reference manual
torch.cummin is a PyTorch function for computing the cumulative minimum. It returns the cumulative minimum along a specified dimension together with the corresponding indices.
Function definition
torch.cummin(input, dim, dtype=None)
Usage examples
Example
import
torch
Compute the cumulative minimum
x
=
torch.
tensor
(
[
3
,
1
,
4
,
1
,
5
,
9
,
2
,
6
]
)
values
,
indices
=
torch.
cummin
(
x
,
dim
=
0
)
(
"Input:"
,
x
)
(
"Cumulative minimum:"
,
values
)
(
"Minimum value indices:"
,
indices
)
2D tensor
x
=
torch.
tensor
(
[
[
3
,
1
,
4
]
,
[
1
,
5
,
9
]
,
[
2
,
6
,
5
]
]
,
dtype
=
torch.
float32
)
Cumulative by column
values_col
,
indices_col
=
torch.
cummin
(
x
,
dim
=
0
)
(
"nCumulative by column:"
)
(
"Cumulative minimum:"
)
(
values_col
)
(
"Indices:"
)
(
indices_col
)
Cumulative by row
values_row
,
indices_row
=
torch.
cummin
(
x
,
dim
=
1
)
(
"nCumulative by row:"
)
(
"Cumulative minimum:"
)
(
values_row
)