





ptEx1
import torch
t1 = torch.FloatTensor([[1,2],[3,4]])
print(t1)
print(type(t1))
print(t1.size())
#크기 size
print()
t2 = torch.tensor([[1,2],[3,4]], dtype=torch.float32)
print(t2)
print(type(t2))
print()
#------------------------------------------------------------
print(t2.numpy())
#ndarray 객체로 가져올 수 있음.
print(type(t2.numpy()))
print()
import numpy as np
ndata = np.array([[1,2,3,4],[5,6,7,8]], dtype=np.float32)
t3 = torch.from_numpy(ndata)
#복사해서 쓰는게 아니라 공유하는 사이 이다.
print(t3)
print(type(t3))
#-----------------------------------------------------------

ptEx2
import torch
#텐서간 타입이 다르면 연산 x , FloatTensor 과 DoubleTensor 간 사칙연산 오류남
t1 = torch.tensor([1,2,3])
t2 = torch.tensor([5,6,7])
print(t1)
print(t2)
print()
t3 = t1 + 30
print(t3)
#tensor([31, 32, 33])
print()
t4 = t1 + t2
print(t4)
#tensor([ 6, 8, 10])
#---------------------------------------------------------------------
t5 = torch.tensor([[10,20,30],[40,50,60]])
print(t5)
print()
print(t5 + t1)
print()
#---------------------------------------------------------------------

ptEx3
import torch
t1 = torch.linspace(0,3,10)
print(t1)
print()
print(torch.exp(t1))
print(torch.log(t1))
print(torch.cos(t1))
print(torch.sqrt(t1))
print(torch.mean(t1))
print(torch.std(t1))
print()
#--------------------------------------------
t2 = torch.tensor([[2,4,6],[7,3,5]])
print(t2)
print()
print(torch.max(t2))
#axis=0, axis=1 == dim=0, dim=1
print()
print(torch.max(t2, dim=1))
#values=tensor([6, 7]), 각 행마다 큰거
#indices=tensor([2, 0])) 인덱스
print()
print(torch.max(t2, dim=1)[0])
print(torch.max(t2, dim=1)[1])
# 하나의 객체 = torch.return_types.max( 이것에 대한 객체를 가져오고 싶을때,
# [0]은 tensor([6, 7]) = value 값, [1]은 tensor([2,0]) = index 값
'AI' 카테고리의 다른 글
| Day67_Ai(5)_Pm (0) | 2025.10.31 |
|---|---|
| Day67_Ai(5)_Am (0) | 2025.10.31 |
| Day66_Ai(4)_Pm / 딥러닝전 설치 (0) | 2025.10.30 |
| Day66_Ai(4)_Am (0) | 2025.10.30 |
| Day65_Ai(3)_Pm (0) | 2025.10.29 |