x = torch.empty(5, 3)
print(x)
打印结果:
tensor([[1.0102e-38, 1.0194e-38, 3.6736e-39],
[8.3572e-39, 4.5918e-39, 4.5918e-39],
[4.0408e-39, 4.5918e-39, 4.7755e-39],
[8.5408e-39, 8.3571e-39, 4.5918e-39],
[4.6837e-39, 4.0408e-39, 4.5918e-39]])
x = torch.rand(5, 3)
print(x)
打印结果:
tensor([[0.1306, 0.2627, 0.1585],
[0.8739, 0.0200, 0.4470],
[0.6009, 0.5557, 0.1189],
[0.5708, 0.4116, 0.6806],
[0.0506, 0.6534, 0.2358]])
x = torch.zeros(5, 3, dtype=torch.long)
print(x)
tensor([[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]])
x = torch.tensor([5.5, 3])
print(x)
输出结果
tensor([5.5000, 3.0000])
x = tensor([5.5000, 3.0000])
x = x.new_ones(5, 3, dtype=torch.double)
print(x)
输出结果
tensor([[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.]], dtype=torch.float64)
x = torch.rand_like(x, dtype=torch.float)
print(x)
输出结果
tensor([[0.0996, 0.3518, 0.2875],
[0.2665, 0.5578, 0.1388],
[0.3313, 0.8641, 0.5232],
[0.8819, 0.6924, 0.9274],
[0.8298, 0.4196, 0.1312]])
print(x.size())