[Pytorch 노트] 3. 수학적 연산

Depth Eye 공식 계정-01-03-mp4-텐서 연산 및 선형 회귀

토치.추가()

기능: 요소별로 요소를 계산합니다 input+alpha×other.

torch.add(input,
          alpha=1,
          other,
          out=None)

입력: 텐서,
알파: 실수인 other의 계수,
other: 입력과 동일한 형태의 텐서.

import torch

t1 = torch.tensor([[2, 3], [4, 5]])
t2 = torch.tensor([[1, 1], [2, 2]])
t = torch.add(t1, alpha=2, other=t2)
print(t)

산출:

tensor([[4, 5],
        [8, 9]])

토치.sub()

기능: 요소별로 요소를 계산합니다 input-alpha×other.

torch.sub(input,
          alpha=1,
          other,
          out=None)

입력: 텐서,
알파: 실수인 other의 계수,
other: 입력과 동일한 형태의 텐서.

import torch

t1 = torch.tensor([[2, 3], [4, 5]])
t2 = torch.tensor([[1, 1], [2, 2]])
t = torch.add(t1, alpha=2, other=t2)
print(t)

산출:

tensor([[0, 1],
        [0, 1]])

토치.mul()

功能:逐元素计算outi = inputi × otheri out_i=input_i \times other_it _=_ _×다른 사람 _ _ _

torch.mul(input,
          other)

입력: 텐서,
기타: 입력과 동일한 크기의 텐서.
기타는 브로드캐스팅을 지원합니다. 즉, 숫자를 다른 사람에게만 전달할 수 있으며, 토치는 브로드캐스트 메커니즘을 사용하여 동일한 크기의 텐서가 됩니다.

import torch

t1 = torch.tensor([[9, 12], [15, 18]])
t2 = torch.tensor([[3, 3], [2, 2]])
t = torch.mul(t1, other=t2)
print(t)

산출:

tensor([[27, 36],
        [30, 36]])

토치.div()

함수: 요소별 계산 outi = inputiother out_i=\frac{input_i}{other}t _=다른 사람 _ __ _

torch.div(input,
          other)

입력: 텐서;
기타: 입력과 크기가 같고 요소가 0이 될 수 없는 텐서.
기타는 브로드캐스팅을 지원합니다. 즉, 숫자를 다른 사람에게만 전달할 수 있으며, 토치는 브로드캐스트 메커니즘을 사용하여 동일한 크기의 텐서가 됩니다.

import torch

t1 = torch.tensor([[9, 12], [4, 6]])
t2 = torch.tensor([[3, 3], [2, 2]])
t = torch.div(t1, other=t2)
print(t)

산출:

tensor([[3., 4.],
        [2., 3.]])

토치.addcmul()

功能:逐元素计算outi = inputi + value × 텐서 1 i × 텐서 2 i out_i=input_i+value \times tensor1_i \times tensor2_it _=_ _+v a l u e×텐서 1 _ _ _×텐서 2 _ _ _

torch.addcmul(input,
              value=1,
              tensor1,
              tensor2,
              out=None)

입력: 입력 텐서;
값: 수식 참조, 실수;
tensor1: 입력과 동일한 모양의 텐서, 수식 참조;
tensor2: 입력과 동일한 모양의 텐서, 수식 참조.

import torch

t1 = torch.tensor([[2., 3.], [4., 5.]])
t2 = torch.tensor([[4., 6.], [8., 10.]])
t3 = torch.tensor([[2., 2.], [2., 2.]])
t = torch.addcmul(t1, value=2, tensor1=t2, tensor2=t3)
print(t)

산출:

tensor([[18., 27.],
        [36., 45.]])

토치.addcdiv()

功能:逐元素计算outi = inputi + value × 텐서 1 itensor 2 i out_i=input_i+value \times\frac{tensor1_i}{tensor2_i}t _=_ _+v a l u e×텐서 2 _ _ _텐서 1 _ _ _

torch.addcdiv(input,
              value=1,
              tensor1,
              tensor2,
              out=None)

입력: 입력 텐서;
값: 수식 참조, 실수;
tensor1: 입력과 동일한 모양의 텐서, 수식 참조;
tensor2: 입력과 동일한 모양이지만 0은 요소에 나타날 수 없는 텐서, 수식 참조.
참고: 입력, tensor1 및 tensor2의 내용은 부동 소수점이어야 합니다. 정수를 사용하면 다음 오류가 보고됩니다.

RuntimeError: addcdiv를 사용한 정수 나누기는 더 이상 지원되지 않으며 향후 릴리스에서는 addcdiv가 tensor1과 tensor2의 실제 나누기를 수행합니다. 과거 addcdiv 동작은 정수 입력의 경우 (input + value * torch.trunc(tensor1 / tensor2)).to(input.dtype) 으로, 부동 소수점 입력의 경우 (input + value * tensor1 / tensor2) 로 구현될 수 있습니다. 향후 addcdiv 동작은 모든 dtype에 대해 후자의 구현(입력 + 값 * tensor1 / tensor2)입니다.

import torch

t1 = torch.tensor([[2., 3.], [4., 5.]])
t2 = torch.tensor([[4., 6.], [8., 10.]])
t3 = torch.tensor([[2., 2.], [2., 2.]])
t = torch.addcdiv(t1, value=2, tensor1=t2, tensor2=t3)
print(t)

산출:

tensor([[ 6.,  9.],
        [12., 15.]])

토치.로그()

함수: 요소별로 해결 outi = loge (inputi) out_i=log_e(input_i)t _=o g전자( 입력 _ _)

torch.log(input,
		  out=None)

입력: 풀어야 할 텐서.

import torch

t1 = torch.tensor([[9., -12.], [15., 18.]])
t = torch.log(t1)
print(t)

산출:

tensor([[2.1972,    nan],
        [2.7081, 2.8904]])

토치.log10()

함수: 요소별로 해결 outi = log 10 (inputi) out_i=log_{10}(input_i)t _=o g10( 입력 _ _)

torch.log10(input,
			out=None)

입력: 풀어야 할 텐서.

import torch

t1 = torch.tensor([[9., -12.], [15., 18.]])
t = torch.log10(t1)
print(t)

산출:

tensor([[0.9542,    nan],
        [1.1761, 1.2553]])

토치.log2()

함수: 요소별로 해결 outi = log 2 (inputi) out_i=log_2(input_i)t _=o g2( 입력 _ _)

torch.log2(input,
		   out=None)

입력: 풀어야 할 텐서.

import torch

t1 = torch.tensor([[8., -12.], [16., 18.]])
t = torch.log2(t1)
print(t)

산출:

tensor([[3.0000,    nan],
        [4.0000, 4.1699]])

토치.exp()

함수: 요소별로 해결 outi = einputi out_i=e^{input_i}t _=이자형_ _

torch.exp(input,
		  out=None)

입력: 풀어야 할 텐서.

import math
import torch

t1 = torch.tensor([[-2., 0.], [1., math.log(2.)]])
t = torch.exp(t1)
print(t)

산출:

tensor([[0.1353, 1.0000],
        [2.7183, 2.0000]])

토치.pow()

함수: outi = xiexpointi 요소별 해결 out_i=x_i^{expont_i}t _=엑스엑스포 엔트 _ _ _ _ _

torch.pow(input,
          exponent,
          out=None)

입력: 풀어야 할 텐서.
지수: 입력과 동일한 모양을 갖는 텐서.
지수가 숫자인 경우 토치는 이를 입력과 동일한 모양의 텐서로 브로드캐스팅합니다.

import torch

t1 = torch.tensor([[1., 2.], [3., 4.]])
t2 = torch.tensor([[3., 2.], [4., 2.]])
t3 = torch.pow(t1, 2.)
t4 = torch.pow(t1, t2)
print(t3)
print(t4)

산출:

tensor([[ 1.,  4.],
        [ 9., 16.]])
tensor([[ 1.,  4.],
        [81., 16.]])

텐서.abs()

기능: 요소별로 절대값 요소를 취합니다. outi = ∣ inputi ∣ out_i=|input_i|t _=입력 _ _ _

torch.abs(input,
          out=None)

입력: 풀어야 할 텐서.

import torch

t1 = torch.tensor([[1., -2.], [-3., 4.]])
t = torch.abs(t1)
print(t)

산출:

tensor([[1., 2.],
        [3., 4.]])

텐서.acos()

함수: 요소별로 해결 outi = cos − 1 ( inputi ) out_i=cos^{-1}(input_i)t _=공동 _1 (입력에서__)

torch.acos(input,
           out=None)

입력: 풀어야 할 텐서.

import torch

t1 = torch.randn(4)
print(t1)
t = torch.acos(t1)
print(t)

산출:

tensor([ 0.5100,  0.1678, -0.0250,  0.3119])
tensor([1.0357, 1.4022, 1.5958, 1.2536])

토치.cosh()

함수: 요소별로 해결 outi = cosh (inputi) out_i=cosh(input_i)t _=cos h ( 입력 u t _)
참고:cosh ( x ) = ex + e − x 2 cosh(x)=\frac{e^x+e^{-x}}{2}cos h ( x )=2이자형x +전자 x

torch.cosh(input,
           out=None)

입력: 풀어야 할 텐서.

import torch

t1 = torch.randn(4)
print(t1)
t = torch.cosh(t1)
print(t)

torch.cosh(input,
           out=None)

산출:

tensor([-0.3447, -0.2875, -0.2717, -1.3635])
tensor([1.0600, 1.0416, 1.0371, 2.0828])

토치.cos()

함수: 요소별로 해결 outi = cos (inputi) out_i=cos(input_i)t _=cos ( 입력 _ _ _)

torch.cos(input,
           out=None)

입력: 풀어야 할 텐서.

import torch

t1 = torch.randn(4)
print(t1)
t = torch.cos(t1)
print(t)

torch.cosh(input,
           out=None)

산출:

tensor([-0.6443, -0.8991,  1.2432, -0.3162])
tensor([0.7995, 0.6223, 0.3218, 0.9504])

토치.asin()

공능:축원소 구해 outi = sin − 1 ( inputi ) out_i=sin^{-1}(input_i)t _=나는 n 이다1 (입력에서__)

torch.asin(input,
           out=None)

입력: 풀어야 할 텐서.

import torch

t1 = torch.randn(4)
print(t1)
t = torch.asin(t1)
print(t)

산출:

tensor([-0.7372, -0.0238, -1.8213, -0.0912])
tensor([-0.8289, -0.0238,     nan, -0.0913])

토치.atan()

공능:축원소 구해 outi = tan − 1 ( inputi ) out_i=tan^{-1}(input_i)t _=t a n1 (입력에서__)

torch.atan(input,
           out=None)

입력: 풀어야 할 텐서.

import torch

t1 = torch.randn(4)
print(t1)
t = torch.atan(t1)
print(t)

산출:

tensor([ 0.3620, -0.6551,  1.0304,  2.1545])
tensor([ 0.3474, -0.5799,  0.8003,  1.1362])

토치.atan2()

功能:逐元素求解outi = tan − 1 ( inputiotheri ) out_i=tan^{-1}(\frac{input_i}{other_i})t _=t a n- 1 (다른 사람 _ _ __ _)

torch.atan(input,
		   other,
           out=None)

입력: 풀어야 할 텐서.

import torch

t1 = torch.randn(4)
print(t1)
t2 = torch.randn(4)
print(t2)
t = torch.atan2(t1, t2)
print(t)

산출:

tensor([ 1.9372,  0.7993, -1.4123,  0.4260])
tensor([-1.5106,  1.2147, -1.4479,  0.1674])
tensor([ 2.2331,  0.5820, -2.3686,  1.1963])

추천

출처blog.csdn.net/xhyu61/article/details/133044585