20220924

강태공·2022년 9월 25일
0

텐서초기화

-텐서의 속성(shape, dtype, device) 확인하기

tensor = torch.rand(3,4)
print(f"Shape of tensor: {tensor.shape}")
print(f"Datatype of tensor: {tensor.dtype}")
print(f"Device tensor is stored on: {tensor.device}"

-난수나 상수값을 사용하기

  shape = (2,3,)
  rand_tensor = torch.rand(shape)
  ones_tensor = torch.ones(shape)
  zeros_tensor = torch.zeros(shape)

-다른 텐서에서 생성하기

  x_ones = torch.ones_like(x_data)
  print(f"Ones Tensor: \n {x_ones} \n")
  x_rand = torch.rand_like(x_data, dtype=torch.float)
  
  print(f"Random Tensor: \n {x_rand} \n")

like = 똑같은 shape의 텐서를 만들기
value는 0, 1, 난수로 설정

List(Python) vs. array(NP) vs. Tensor(Torch)

  • 파이썬 리스트 [1,2]
  • Numpy 배열(Array)

Numpy 배열 정복하자!

배열의 크기 변형 = reshape !!!!!아주중요

0개의 댓글