*Memos:
- My post explains min() and max().
- My post explains minimum() and maximum().
- My post explains fmin() and fmax().
- My post explains argmin() and argmax().
- My post explains aminmax(), amin() and amax().
- My post explains kthvalue() and topk().
- My post explains cumsum() and cumprod().
cummin() can get two of the 0D or more D tensors of zero or more cumulative minima and their indices from the 0D or more D tensors of zero or more elements as shown below:
*Memos:
-
cummin()
can be used with torch or a tensor. - The 1st argument(
input
) withtorch
or using a tensor(Required-Type:tensor
ofint
,float
orbool
). - The 2nd argument with
torch
or the 1st argument isdim
(Required-Type:int
). - There is
out
argument withtorch
(Optional-Default:None
-Type:tuple
(tensor
,tensor
) orlist
(tensor
,tensor
)): *Memos:-
out=
must be used. -
My post explains
out
argument.
-
import torch
my_tensor = torch.tensor([5, 8, 4, 6, 9, 1, 7, 0])
torch.cummin(input=my_tensor, dim=0)
my_tensor.cummin(dim=0)
torch.cummin(input=my_tensor, dim=-1)
# torch.return_types.cummin(
# values=tensor([5, 5, 4, 4, 4, 1, 1, 0]),
# indices=tensor([0, 0, 2, 2, 2, 5, 5, 7]))
my_tensor = torch.tensor([[5, 8, 4, 6],
[9, 1, 7, 0],
[3, 6, 2, 4]])
torch.cummin(input=my_tensor, dim=0)
torch.cummin(input=my_tensor, dim=-2)
# torch.return_types.cummin(
# values=tensor([[5, 8, 4, 6], [5, 1, 4, 0], [3, 1, 2, 0]]),
# indices=tensor([[0, 0, 0, 0], [0, 1, 0, 1], [2, 1, 2, 1]]))
torch.cummin(input=my_tensor, dim=1)
torch.cummin(input=my_tensor, dim=-1)
# torch.return_types.cummin(
# values=tensor([[5, 5, 4, 4], [9, 1, 1, 0], [3, 3, 2, 2]]),
# indices=tensor([[0, 0, 2, 2], [0, 1, 1, 3], [0, 0, 2, 2]]))
my_tensor = torch.tensor([[5., 8., 4., 6.],
[9., 1., 7., 0.],
[3., 6., 2., 4.]])
torch.cummin(input=my_tensor, dim=0)
# torch.return_types.cummin(
# values=tensor([[5., 8., 4., 6.], [5., 1., 4., 0.], [3., 1., 2., 0.]]),
# indices=tensor([[0, 0, 0, 0], [0, 1, 0, 1], [2, 1, 2, 1]]))
my_tensor = torch.tensor([[True, False, True, False],
[False, True, False, True],
[True, False, True, False]])
torch.cummin(input=my_tensor, dim=0)
# torch.return_types.cummin(
# values=tensor([[True, False, True, False],
# [False, False, False, False],
# [False, False, False, False]]),
# indices=tensor([[0, 0, 0, 0],
# [1, 0, 1, 0],
# [1, 2, 1, 2]]))
cummax() can get two of the 0D or more D tensors of zero or more cumulative maxima and their indices from the 0D or more D tensors of zero or more elements as shown below:
-
cummax()
can be used withtorch
or a tensor. - The 1st argument(
input
) withtorch
or using a tensor(Required-Type:tensor
ofint
,float
orbool
). - The 2nd argument with
torch
or the 1st argument isdim
(Required-Type:int
). - There is
out
argument withtorch
(Optional-Default:None
-Type:tuple
(tensor
,tensor
) orlist
(tensor
,tensor
)): *Memos:-
out=
must be used. -
My post explains
out
argument.
-
import torch
my_tensor = torch.tensor([5, 8, 4, 6, 9, 1, 7, 0])
torch.cummax(input=my_tensor, dim=0)
my_tensor.cummax(dim=0)
torch.cummax(input=my_tensor, dim=-1)
# torch.return_types.cummax(
# values=tensor([5, 8, 8, 8, 9, 9, 9, 9]),
# indices=tensor([0, 1, 1, 1, 4, 4, 4, 4]))
my_tensor = torch.tensor([[5, 8, 4, 6],
[9, 1, 7, 0],
[3, 6, 2, 4]])
torch.cummax(input=my_tensor, dim=0)
torch.cummax(input=my_tensor, dim=-2)
# torch.return_types.cummax(
# values=tensor([[5, 8, 4, 6], [9, 8, 7, 6], [9, 8, 7, 6]]),
# indices=tensor([[0, 0, 0, 0], [1, 0, 1, 0], [1, 0, 1, 0]]))
torch.cummax(input=my_tensor, dim=1)
torch.cummax(input=my_tensor, dim=-1)
# torch.return_types.cummax(
# values=tensor([[5, 8, 8, 8], [9, 9, 9, 9], [3, 6, 6, 6]]),
# indices=tensor([[0, 1, 1, 1], [0, 0, 0, 0], [0, 1, 1, 1]]))
my_tensor = torch.tensor([[5., 8., 4., 6.],
[9., 1., 7., 0.],
[3., 6., 2., 4.]])
torch.cummax(input=my_tensor, dim=0)
# torch.return_types.cummax(
# values=tensor([[5., 8., 4., 6.], [9., 8., 7., 6.], [9., 8., 7., 6.]]),
# indices=tensor([[0, 0, 0, 0], [1, 0, 1, 0], [1, 0, 1, 0]]))
my_tensor = torch.tensor([[True, False, True, False],
[False, True, False, True],
[True, False, True, False]])
torch.cummax(input=my_tensor, dim=0)
# torch.return_types.cummax(
# values=tensor([[True, False, True, False],
# [True, True, True, True],
# [True, True, True, True]]),
# indices=tensor([[0, 0, 0, 0],
# [0, 1, 0, 1],
# [2, 1, 2, 1]]))
Top comments (0)