Introduction to PyTorch - Springer

Creating Tensors with NumPy In [1]: a = torch.tensor(numpy.array([[0.1, 0.2],[0.3, 0.4]])) In [2]: a Out[2]: tensor([[0.1000, 0.2000], [0.3000, 0.4000]], dtype=torch.float64) In [3]: a.shape Out[3]: torch.Size([2, 2]) We can also create a tensor from an existing NumPy n-dimensional array using the from_numpy function. Listing 2-6 demonstrates ... ................
................