torch.zerosとtorch.zeros_likeの違いが気になったので書く。
torch.zerosの使い方
値が0のtensorを返す。
>>> torch.zeros(3, 2)
tensor([[0., 0.],
[0., 0.],
[0., 0.]])
>>> torch.zeros(3)
tensor([0., 0., 0.])
torch.zeros_likeの使い方
あるtensorの値をすべて0にしたいときに使う。
>>> input = torch.empty(3, 2)
tensor([[3.2561e+09, 3.0936e-41],
[0.0000e+00, 0.0000e+00],
[3.2557e+09, 3.0936e-41]])
>>> torch.zeros_like(input)
tensor([[0., 0.],
[0., 0.],
[0., 0.]])
上の例はinputの値をすべて0にしている。