Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Super Kai (Kazuya Ito)
Super Kai (Kazuya Ito)

Posted on • Edited on

     

minimum and maximum in PyTorch

Buy Me a Coffee

*Memos:

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

*Memos:

  • minimum() 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 withtorch or the 1st argument isother(Required-Type:tensor ofint,float orbool).
  • There isout argument withtorch(Optional-Default:None-Type:tensor):*Memos:
    • out= must be used.
    • My post explainsout argument.
  • nan is taken if there are a number andnan.
importtorchtensor1=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]]])
Enter fullscreen modeExit fullscreen mode

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

*Memos:

  • maximum() 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 withtorch or the 1st argument isother(Required-Type:tensor ofint,float orbool).
  • There isout argument withtorch(Optional-Default:None-Type:tensor):*Memos:
    • out= must be used.
    • My post explainsout argument.
  • nan is taken if there are a number andnan.
importtorchtensor1=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]]])
Enter fullscreen modeExit fullscreen mode

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

I'm a web developer.Buy Me a Coffee: ko-fi.com/superkaiSO: stackoverflow.com/users/3247006/super-kai-kazuya-itoX(Twitter): twitter.com/superkai_kazuyaFB: facebook.com/superkai.kazuya
  • Joined

More fromSuper Kai (Kazuya Ito)

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp