Suppose we have following code
a = torch.randn(3, 2)
b1 = a.new()
b2 = torch.empty_like(a)
what is the potential difference between b1
and b2
?
Suppose we have following code
a = torch.randn(3, 2)
b1 = a.new()
b2 = torch.empty_like(a)
what is the potential difference between b1
and b2
?
a.new()
will return a tensor of zero size (namely, no data in it) with the same type of a
, while torch.empty_like(b1)
will return a tensor with the same size and type of b1
.
You may regard torch.empty_like(a)
as a.new().resize_as_(a)
.