Road PyTorch learning

What PyTorch that?

A: PyTorch is a science-based computing software package for Python

Why Pytorch:

  • Alternatively NumPy using functionality of the GPU (ndarrays Numpy not in operation on the GPU)
  • Providing maximum flexibility and speed in depth study and research platform

Tensor (Tensors)

Tensors and the PyTorch Numpy of ndarrays similar, but the operation can Tensor GPU

How to create a tensor

  • Create an uninitialized tensor
import torch  #引入的库后续不在引入
x = torch.empty(5,3)
print(x)

out

tensor([[0.0000e+00, 0.0000e+00, 0.0000e+00],
        [0.0000e+00, 0.0000e+00, 0.0000e+00],
        [0.0000e+00, 0.0000e+00, 0.0000e+00],
        [0.0000e+00, 1.7600e-42, 0.0000e+00],
        [0.0000e+00, 1.2101e+25, 0.0000e+00]])
  • Create an initialization tensor with rand
x = torch.rand(3,5) 

out

tensor([[0.9412, 0.3695, 0.6118, 0.7682, 0.1253],
        [0.7228, 0.5174, 0.3550, 0.9220, 0.3523],
        [0.3066, 0.3015, 0.7750, 0.2444, 0.2413]])
Published 16 original articles · won praise 0 · Views 943

Guess you like

Origin blog.csdn.net/qq_44157281/article/details/103335721