왜 torch.zeros를 쓰지 않고 torch.new_zeros를 사용할까
딥러닝 꿀팁

왜 torch.zeros를 쓰지 않고 torch.new_zeros를 사용할까

by handzoo 2023. 5. 16.

torch.zeros를 사용하면 torch.Tensor을 scratch부터 만들어내는 것이고

torch.new_zeros를 사용하면 이전에 사용하던 tensor A와 같은 device를 갖게 된다.

 

cpu를 사용할 때 일일이 cpu 설정을 해주지 않고 (gpu에 대해서도 마찬가지)

이전 tensor A에서 사용하던 device를 계속 이어받아 생성하게 된다.

 

1
2
3
shape = (3,4,5)
= torch.ones((2,3), dtype=torch.int8).
= A.new_zeros((shape))
cs

 

new_zeros 뿐 아니라 new 뒤에 올 수 있는 것은 new_tensor, new_full, new_empty, new_ones, new_zeros가 있다.


TOP

Designed by 티스토리