#텐서 생성
import torch
print(torch.tensor([1,2,3]))
print(torch.Tensor([[1,2,3],[4,5,6]]))
print(torch.LongTensor([1,2,3]))
print(torch.FloatTensor([1,2,3]))
#텐서 속성
import torch
tensor = torch.rand(1,2) #0과 1 사이의 무작위 숫자를 균등분포로 생성
print(tensor)
print(tensor.shape)
print(tensor.dtype)
print(tensor.device)
#텐서 차원 변환
import torch
tensor = torch.rand(1,2)
print(tensor)
print(tensor.shape)
tensor = tensor.reshape(2,1)
print(tensor)
print(tensor.shape)
#텐서 자료형 설정
import torch
tensor = torch.rand((3,3), dtype = torch.float)
print(tensor)
#텐서 GPU 장치 설정
import torch
device = "cuda" if torch.cuda.is_available() else "cpu"
cpu = torch.FloatTensor([1,2,3])
gpu = torch.cuda.FloatTensor([1,2,3])
tensor = torch.rand((1,1), device = device)
print(device)
print(cpu)
print(gpu)
print(tensor)
#텐서 장치 변환
import torch
cpu = torch.FloatTensor([1,2,3])
gpu = cpu.cuda()
gpu2cpu = gpu.cpu()
cpu2gpu = cpu.to("cuda")
print(cpu)
print(gpu)
print(gpu2cpu)
print(cpu2gpu)
#넘파이 배열의 텐서 변환
import torch
import numpy as np
ndarry = np.array([1,2,3], dtype=np.uint8)
print(torch.tensor(ndarry))
print(torch.Tensor(ndarry))
print(torch.from_numpy(ndarry))
#텐서의 넘파이 배열 변환
import torch
tensor = torch.cuda.FloatTensor([1,2,3])
ndarry = tensor.detach().cpu().numpy()
print(ndarry)
print(type(ndarry))
#성별에 따른 키 차이 검정
import numpy as np
import pandas as pd
import seaborn as sns
from scipy import stats
from matplotlib import pyplot as plt
man_height = stats.norm.rvs(loc=170, scale=10, size=500, random_state=1)
woman_height = stats.norm.rvs(loc=150, scale=10, size=500, random_state=1)
X = np.concatenate([man_height, woman_height])
Y = ["man"] * len(man_height) + ["woman"] * len(woman_height)
df = pd.DataFrame(list(zip(X,Y)), columns = ["X", "Y"])
fig = sns.displot(data = df, x="X", hue = "Y", kind = "kde")
fig.set_axis_labels("cm", "count")
plt.show()