Tensors (张量)
https://pytorch123.com/SecondSection/what_is_pytorch/
from __future__ import print_function
将__future__函数的 print_function 功能导入
构造一个5x3矩阵,不初始化。
x = torch.empty(5, 3)
print(x)
tensor(1.00000e-04 *
[[-0.0000, 0.0000, 1.5135],
[ 0.0000, 0.0000, 0.0000],
[ 0.0000, 0.0000, 0.0000],
[ 0.0000, 0.0000, 0.0000],
[ 0.0000, 0.0000, 0.0000]])
构造一个随机初始化的矩阵:
x = torch.rand(5, 3)
print(x)
输出:
tensor([[ 0.6291, 0.2581, 0.6414],
[ 0.9739, 0.8243, 0.2276],
[ 0.4184, 0.1815, 0.5131],
[ 0.5533, 0.5440, 0.0718],
[ 0.2908, 0.1850, 0.5297]])
构造一个矩阵全为 0,而且数据类型是 long.