Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

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

Posted on

remainder in PyTorch

Buy Me a Coffee

*Memos:

remainder() can do the modulo(mod) calculation ofPython’s modulus operation with two of the 0D or more D tensors of zero or more elements or the 0D or more D tensor of zero or more elements and a scalar, getting the 0D or more D tensor of zero or more elements as shown below:

*Memos:

  • remainder() can be used withtorch or a tensor.
  • The 1st argument(input) withtorch(Type:tensor orscalar ofint orfloat) or using a tensor(Type:tensor ofint orfloat)(Required). *torch must use a scalar withoutinput=.
  • The 2nd argument withtorch or the 1st argument with a tensor isother(Required-Type:tensor orscalar ofint orfloat).
  • There isout argument withtorch(Optional-Default:None-Type:tensor):*Memos:
    • out= must be used.
    • My post explainsout argument.
  • Setting0(int) toother getsZeroDivisionError.
  • The combination of a scalar(input) and a scalar(other) cannot be used.
  • The result has the same sign asother.
importtorchtensor1=torch.tensor([9,7,6])tensor2=torch.tensor([[4,-4,3],[-2,5,-5]])torch.remainder(input=tensor1,other=tensor2)tensor1.remainder(other=tensor2)# tensor([[1, -1, 0], [-1, 2, -4]])torch.remainder(9,other=tensor2)# tensor([[1, -3, 0], [-1, 4, -1]])torch.remainder(input=tensor1,other=4)# tensor([1, 3, 2])tensor1=torch.tensor([-9,-7,-6])tensor2=torch.tensor([[4,-4,3],[-2,5,-5]])torch.remainder(input=tensor1,other=tensor2)# tensor([[3, -3, 0],torch.remainder(-9,other=tensor2)# tensor([[3, -1, 0], [-1, 1, -4]])torch.remainder(input=tensor1,other=4)# tensor([3, 1, 2])tensor1=torch.tensor([9.75,7.08,6.26])tensor2=torch.tensor([[4.26,-4.54,3.37],[-2.16,5.43,-5.98]])torch.remainder(input=tensor1,other=tensor2)# tensor([[1.2300, -2.0000, 2.8900],#         [-1.0500, 1.6500, -5.7000]])torch.remainder(9.75,other=tensor2)# tensor([[1.2300, -3.8700, 3.0100], [-1.0500, 4.3200, -2.2100]])torch.remainder(input=tensor1,other=4.26)# tensor([1.2300, 2.8200, 2.0000])
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