Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 18, 2024 04:07 am GMT

aminmax(), amin() and amax() in PyTorch

*Memos:

aminmax() can get the one or more minimum and maximum values of a 0D or more D tensor as shown below:

*Memos:

  • aminmax() can be called both from torch and a tensor.
  • Setting a dimension(dim) to the 2nd argument with torch or the 1st argument with a tensor gets zero or more 1st minimum and maximum values. *You must use dim= to set a dimension.
  • Zero or more integers, floating-point numbers or boolean values can be used so zero or more complex numbers cannot be used except the 0D tensor of a complex number with dim=0 or dim=-1.
import torchmy_tensor = torch.tensor([[5, 4, 7, 7],                          [6, 5, 3, 5],                          [3, 8, 9, 3]])torch.aminmax(my_tensor)my_tensor.aminmax()# torch.return_types.aminmax(# min=tensor(3),# max=tensor(9))torch.aminmax(my_tensor, dim=0)my_tensor.aminmax(dim=0)torch.aminmax(my_tensor, dim=-2)my_tensor.aminmax(dim=-2)# torch.return_types.aminmax(# min=tensor([3, 4, 3, 3]),# max=tensor([6, 8, 9, 7]))torch.aminmax(my_tensor, dim=1)my_tensor.aminmax(dim=1)torch.aminmax(my_tensor, dim=-1)my_tensor.aminmax(dim=-1)# torch.return_types.aminmax(# min=tensor([4, 3, 3]),# max=tensor([7, 6, 9]))my_tensor = torch.tensor([[5., 4., 7., 7.],                          [6., True, 3., 5.],                          [3., 8., False, 3.]])torch.aminmax(my_tensor, dim=0)my_tensor.aminmax(dim=0)torch.aminmax(my_tensor, dim=-2)my_tensor.aminmax(dim=-2)# torch.return_types.aminmax(# min=tensor([3., 1., 0., 3.]),# max=tensor([6., 8., 7., 7.]))my_tensor = torch.tensor(5+7j)torch.aminmax(my_tensor, dim=0)my_tensor.aminmax(dim=0)torch.aminmax(my_tensor, dim=-1)my_tensor.aminmax(dim=-1)# torch.return_types.aminmax(# min=tensor(5.+7.j),# max=tensor(5.+7.j))

amin() can get the one or more minimum values of a 0D or more D tensor as shown below:

*Memos:

  • amin() can be called both from torch and a tensor.
  • Setting a dimension(dim) to the 2nd argument with torch or the 1st argument with a tensor gets zero or more 1st minimum values. *You must use dim= to set a dimension.
  • Only zero or more integers, floating-point numbers or boolean values can be used so zero or more complex numbers cannot be used.
import torchmy_tensor = torch.tensor([[5, 4, 7, 7],                          [6, 5, 3, 5],                          [3, 8, 9, 3]])torch.amin(my_tensor)my_tensor.amin()# tensor(3)torch.amin(my_tensor, dim=0)my_tensor.amin(dim=0)torch.amin(my_tensor, dim=-2)my_tensor.amin(dim=-2)# tensor([3, 4, 3, 3])torch.amin(my_tensor, dim=1)my_tensor.amin(dim=1)torch.amin(my_tensor, dim=-1)my_tensor.amin(dim=-1)# tensor([4, 3, 3])my_tensor = torch.tensor([[5., 4., 7., 7.],                          [6., True, 3., 5.],                          [3., 8., False, 3.]])torch.amin(my_tensor, dim=0)my_tensor.amin(dim=0)torch.amin(my_tensor, dim=-2)my_tensor.amin(dim=-2)# tensor([3., 1., 0., 3.])

amax() can get the one or more maximum values of a 0D or more D tensor as shown below:

*Memos:

  • amax() can be called both from torch and a tensor.
  • Setting a dimension(dim) to the 2nd argument with torch or the 1st argument with a tensor gets zero or more 1st maximum values. *You must use dim= to set a dimension.
  • Only zero or more integers, floating-point numbers or boolean values can be used so zero or more complex numbers cannot be used.
import torchmy_tensor = torch.tensor([[5, 4, 7, 7],                          [6, 5, 3, 5],                          [3, 8, 9, 3]])torch.amax(my_tensor)my_tensor.amax()# tensor(9)torch.amax(my_tensor, dim=0)my_tensor.amax(dim=0)torch.amax(my_tensor, dim=-2)my_tensor.amax(dim=-2)# tensor([6, 8, 9, 7])torch.amax(my_tensor, dim=1)my_tensor.amax(dim=1)torch.amax(my_tensor, dim=-1)my_tensor.amax(dim=-1)# tensor([7, 6, 9])my_tensor = torch.tensor([[5., 4., 7., 7.],                          [6., True, 3., 5.],                          [3., 8., False, 3.]])torch.amax(my_tensor, dim=0)my_tensor.amax(dim=0)torch.amax(my_tensor, dim=-2)my_tensor.amax(dim=-2)# tensor([6., 8., 7., 7.])

Original Link: https://dev.to/hyperkai/aminmax-amin-and-amax-in-pytorch-25ji

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To