remainder in PyTorch
Buy Me a Coffee☕
*Memos:
- My post explains add().
- My post explains sub().
- My post explains mul().
- My post explains div().
- My post explains fmod().
remainder() can do the modulo(mod) calculation of Python’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 with torch or a tensor.
- The 1st argument(input) with torch(Type:tensor or scalar of int or float) or using a tensor(Type:tensor of int or float)(Required). *torch must use a scalar without input=.
- The 2nd argument with torch or the 1st argument with a tensor is other(Required-Type:tensor or scalar of int or float).
- There is out argument with torch(Optional-Default:None-Type:tensor):
*Memos:
- out= must be used.
- My post explains out argument.
- Setting 0(int) to other gets ZeroDivisionError.
- The combination of a scalar(input) and a scalar(other) cannot be used.
- The result has the same sign as other.
import torch tensor1 = 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])
The above is the detailed content of remainder in PyTorch. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

How does Uvicorn continuously listen for HTTP requests? Uvicorn is a lightweight web server based on ASGI. One of its core functions is to listen for HTTP requests and proceed...

Fastapi ...

Using python in Linux terminal...

Understanding the anti-crawling strategy of Investing.com Many people often try to crawl news data from Investing.com (https://cn.investing.com/news/latest-news)...
