minimum() and maximum() in PyTorch

Buy Me a Coffee☕

*Memos:

My post explains min() and max().

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().

minimum() can get th…


This content originally appeared on DEV Community and was authored by Super Kai (Kazuya Ito)

Buy Me a Coffee

*Memos:

minimum() can get the 0D or more D tensor of zero or more minimum elements prioritizing nan from two of the 0D or more D tensors of zero or more elements as shown below:

*Memos:

  • minimum() can be used with torch or a tensor.
  • The 1st argument(input) with torch or using a tensor(Required-Type:tensor of int, float or bool).
  • The 2nd argument with torch or the 1st argument is other(Required-Type:tensor of int, float or bool).
  • There is out argument with torch(Optional-Type:tensor): *Memos:
    • out= must be used.
    • My post explains out argument.
  • nan is taken if there are a number and nan.
import torch

tensor1 = torch.tensor([5., float('nan'), 4., float('nan')])
tensor2 = torch.tensor([[7., 8., float('nan'), float('nan')],
                        [-9., 2., 0., -6.]])
torch.minimum(input=tensor1, other=tensor2)
tensor1.minimum(other=tensor2)
# tensor([[5., nan, nan, nan],
#         [-9., nan, 0., nan]])

tensor1 = torch.tensor(5.)
tensor2 = torch.tensor([[[7., 8.], [float('nan'), float('nan')]],
                        [[-9., 2.], [0., -6.]]])
torch.minimum(input=tensor1, other=tensor2)
# tensor([[[5., 5.], [nan, nan]],
#         [[-9., 2.], [0., -6.]]])

tensor1 = torch.tensor(5)
tensor2 = torch.tensor([[[7, 8], [-5, -1]],
                        [[-9, 2], [0, -6]]])
torch.minimum(input=tensor1, other=tensor2)
# tensor([[[5, 5], [-5, -1]],
#         [[-9, 2], [0, -6]]])

tensor1 = torch.tensor(True)
tensor2 = torch.tensor([[[True, False], [True, False]],
                        [[False, True], [False, True]]])
torch.minimum(input=tensor1, other=tensor2)
# tensor([[[True, False], [True, False]],
#         [[False, True], [False, True]]])

maximum() can get the 0D or more D tensor of zero or more maximum elements prioritizing nan from two of the 0D or more D tensors of zero or more elements as shown below:

*Memos:

  • maximum() can be used with torch or a tensor.
  • The 1st argument(input) with torch or using a tensor(Required-Type:tensor of int, float or bool).
  • The 2nd argument with torch or the 1st argument is other(Required-Type:tensor of int, float or bool).
  • There is out argument with torch(Optional-Type:tensor): *Memos:
    • out= must be used.
    • My post explains out argument.
  • nan is taken if there are a number and nan.
import torch

tensor1 = torch.tensor([5., float('nan'), 4., float('nan')])
tensor2 = torch.tensor([[7., 8., float('nan'), float('nan')],
                        [-9., 2., 0., -6.]])
torch.maximum(input=tensor1, other=tensor2)
tensor1.maximum(other=tensor2)
# tensor([[7., nan, nan, nan],
#         [5., nan, 4., nan]])

tensor1 = torch.tensor(5.)
tensor2 = torch.tensor([[[7., 8.], [float('nan'), float('nan')]],
                        [[-9., 2.], [0., -6.]]])
torch.maximum(input=tensor1, other=tensor2)
# tensor([[[7., 8.], [nan, nan]],
#         [[5., 5.], [5., 5.]]])

tensor1 = torch.tensor(5)
tensor2 = torch.tensor([[[7, 8], [-5, -1]],
                        [[-9, 2], [0, -6]]])
torch.maximum(input=tensor1, other=tensor2)
# tensor([[[7, 8], [5, 5]],
#         [[5, 5], [5, 5]]])

tensor1 = torch.tensor(True)
tensor2 = torch.tensor([[[True, False], [True, False]],
                        [[False, True], [False, True]]])
torch.maximum(input=tensor1, other=tensor2)
# tensor([[[True, True], [True, True]],
#         [[True, True], [True, True]]])


This content originally appeared on DEV Community and was authored by Super Kai (Kazuya Ito)


Print Share Comment Cite Upload Translate Updates
APA

Super Kai (Kazuya Ito) | Sciencx (2024-07-15T14:43:48+00:00) minimum() and maximum() in PyTorch. Retrieved from https://www.scien.cx/2024/07/15/minimum-and-maximum-in-pytorch/

MLA
" » minimum() and maximum() in PyTorch." Super Kai (Kazuya Ito) | Sciencx - Monday July 15, 2024, https://www.scien.cx/2024/07/15/minimum-and-maximum-in-pytorch/
HARVARD
Super Kai (Kazuya Ito) | Sciencx Monday July 15, 2024 » minimum() and maximum() in PyTorch., viewed ,<https://www.scien.cx/2024/07/15/minimum-and-maximum-in-pytorch/>
VANCOUVER
Super Kai (Kazuya Ito) | Sciencx - » minimum() and maximum() in PyTorch. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/07/15/minimum-and-maximum-in-pytorch/
CHICAGO
" » minimum() and maximum() in PyTorch." Super Kai (Kazuya Ito) | Sciencx - Accessed . https://www.scien.cx/2024/07/15/minimum-and-maximum-in-pytorch/
IEEE
" » minimum() and maximum() in PyTorch." Super Kai (Kazuya Ito) | Sciencx [Online]. Available: https://www.scien.cx/2024/07/15/minimum-and-maximum-in-pytorch/. [Accessed: ]
rf:citation
» minimum() and maximum() in PyTorch | Super Kai (Kazuya Ito) | Sciencx | https://www.scien.cx/2024/07/15/minimum-and-maximum-in-pytorch/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.