
a = torch.tensor(1, dtype = torch.uint8)
b=a.float()
c=b.double()
default data type은 float32
a=torch.zeros(5): 0으로 초기된 1차원 tensor
b=torch.ones([1,4,3]): 1로 초기된 3차원 tensor
c=torch.zeros_like(b): 크기와 자료형 유지한 채로 원소들만 0으로 초기화, 원본 tensor와 같은 device상에 있는 메모리 주소에 할당됨
d=torch.ones_loke(a): 크기와 자료형 유지한 채로 원소들만 1로 초기화, 원본 tensor와 같은 device상에 있는 메모리 주소에 할당됨
j = torch.rand([2, 3]): 0~1 사이의 연속균등분포에서 추출한 난수로 채워진 특정 크기의 tensor를 생성
k = torch.randn(3): 표준정규분포에서 추출한 난수로 채워진 특정 크기의 tensor를 생성
m = torch.rand_like(k): 크기와 자료형 유지한 채로 [0, 1] 구간의 연속균등분포 난수 tensor
n = torch.randn_like(i): 크기와 자료형 유지한 채로 표준정규분포 난수 tensor
o = torch.arange(start = 1, end = 11, step = 2): 범위 내에서 일정 간격의 값을 가진 tensor (arange=array range) (매개뱐수 생략 가능, 인자 중 하나라도 실수면 dtype은 float로 바뀜, 현재는 int64)
q = torch.empty(5): 초기화 되지 않은 tensor (성능 향상, 메모리 사용 최적화)
q.fill_(3.0): 초기화 되지 않은 tensor에 다른 데이터로 수정, 메모리 주소 유지
t = torch.tensor(s): list로 tensor 생성 (s = [1, 2, 3, 4, 5, 6])
v = torch.from_Numpy(u): numpy 데이터로 tensor 생성 (u = np.array([[0, 1], [2, 3]]))
CPU tensor=legacy constructor?
x = torch.tensor([1, 2, 3, 4, 5, 6])
a = torch.tensor([1, 2, 3])