

그래서 deep learning에서는 GPU가 중요하다.
내 컴퓨터인 M1 mac에서는 둘다 설치가 불가능함.
brew install pyenv
eval "$(pyenv init --path)"
source ~/.zshrc # 혹은 `source ~/.bashrc`
pyenv install 3.10.9
cd /path/to/your/pytorch_study
pyenv local 3.10.9
python -m venv torch # venv 폴더 생성
source ./torch # 가상환경 활성화
pip install --upgrade pip setuptools wheel
pip install torch torchvision torchaudio
pip install jupyterlab
jupyter-lab
'''
scalar
'''
scalar1= torch.tensor([1.])
print(scalar1)
scalar2=torch.tensor([3.])
print(scalar2)
# four basic operation w special character
add_scalar=scalar1+scalar2
sub_scalar=scalar1-scalar2
mul_scalar=scalar1*scalar2
div_scalar=scalar1/scalar2
# four basic operation w torch method
torch.add(scalar1,scalar2)
torch.sub(scalar1,scalar2)
torch.mul(scalar1,scalar2)
torch.div(scalar1,scalar2)
'''
vector: 사칙연산시 각 요소별로 계산됨.
special charactor, method 모두 사용가능.
'''
vector1 = torch.tensor([1.,2.,3.])
print(vector1)
vector2 = torch.tensor([4.,5.,6.,])
print(vector2)
'''
matrix: 2개 이상의 벡터값을 통합하여 구성
+,-,*,/: 벡터와 동일하게 동일위치에 있는 원소과 계산
matmul: 행렬곱
'''
matrix1 = torch.tensor([[1.,2.],[3.,4.]])
matrix2 = torch.tensor([[5.,6.],[7.,8.]])
torch.matmul(matrix1,matrix2)
'''
tensor: 이 차원이상의 배열
tensor의 요소가 행렬인경우 행렬 곱 연산도 가능함
'''
'''
tensor: 이 차원이상의 배열
tensor의 요소가 행렬인경우 행렬 곱 연산도 가능함
'''
tensor1 = torch.tensor([[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]]])
tensor2 = torch.tensor([[[9., 10.], [11., 12.]], [[13., 14.], [15., 16.]]])
# Tensor addition
add_tensor = tensor1 + tensor2
print("Addition:\n", add_tensor)
# Tensor subtraction
sub_tensor = tensor1 - tensor2
print("Subtraction:\n", sub_tensor)
# Tensor multiplication (element-wise)
mul_tensor = tensor1 * tensor2
print("Multiplication:\n", mul_tensor)
# Tensor division (element-wise)
div_tensor = tensor1 / tensor2
print("Division:\n", div_tensor)
# Tensor matrix multiplication
matmul_tensor = torch.matmul(tensor1, tensor2)
print("Matrix Multiplication:\n", matmul_tensor)
