如果不知道怎么开始和安装软件 从这里开始
如果需要GPU版本,请选择CUDA,而不是CPU
PyTorchhttps://pytorch.org/
Python 3.8.13 | packaged by conda-forge | (default, Mar 25 2022, 06:04:10)
[GCC 10.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> x=torch.empty(5,3)
>>> print(x)
tensor([[-8.7848e-11, 4.5785e-41, -8.7479e-11],
[ 4.5785e-41, -8.7848e-11, 4.5785e-41],
[ 2.8026e-45, 0.0000e+00, 0.0000e+00],
[ 4.5785e-41, 0.0000e+00, 0.0000e+00],
[ 0.0000e+00, 4.5785e-41, -9.0661e-11]])
>>> x=torch.rand(7,4)
>>> print(x)
tensor([[0.6772, 0.3902, 0.2330, 0.9701],
[0.6920, 0.7725, 0.3087, 0.0431],
[0.3625, 0.7056, 0.5657, 0.2941],
[0.7590, 0.8172, 0.5953, 0.0298],
[0.1016, 0.5372, 0.0127, 0.6681],
[0.5398, 0.6971, 0.6637, 0.4160],
[0.7463, 0.1475, 0.3829, 0.4958]])
>>> 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],[6.5,5]])
>>> print(x)
tensor([[5.5000, 3.0000],
[6.5000, 5.0000]])
我的领悟:张量等于多维数组(维数大于3)