官方文档解释:

To create a tensor with pre-existing data, use ​​torch.tensor()​​.

To create a tensor with specific size, use ​​torch.*​​ tensor creation ops (see Creation Ops).

To create a tensor with the same size (and similar types) as another tensor, use ​​torch.*_like​​ tensor creation ops (see Creation Ops).

To create a tensor with similar type but different size as another tensor, use ​​tensor.new_*​​ creation ops.

简单来说,

​torch.tensor()​​ 用的最多,一般都用它;

​torch.*​​ 用于创建特殊形式的 tensor,包括 ​​torch.ones()​​、​​torch.zeros()​​等;

​torch.*_like()​​ 用于创建一个与已知 tensor 形状相同的 tensor;

​torch.new_*​​ 用于创建一个与已知 tensor 类型相同的 tensor

最后放一下参数表

torch.tensor(data, dtype=None, device=None, requires_grad=False, pin_memory=False) → Tensor

torch.ones(*size, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) → Tensor

torch.ones_like(input, dtype=None, layout=None, device=None, requires_grad=False) → Tensor

torch.new_ones(size, dtype=None, device=None, requires_grad=False) → Tensor