Learn practical skills, build real-world projects, and advance your career
import torch
import numpy as np
a = torch.ones((2,3), dtype = torch.int32)
b = torch.full((2,3), 9)
c = torch.zeros(3,4)
b.add_(a)
print(b)
tensor([[10., 10., 10.], [10., 10., 10.]])
n1 = torch.tensor([1,2,3], dtype = torch.float32)
n2 = torch.tensor([3,5,6], dtype = torch.float32)
n1*n2
tensor([ 3., 10., 18.])
n1 = torch.tensor([[1,2,3],[7,8,9]], dtype = torch.float32)
n2 = torch.tensor([[1,2],[3,5],[5,6]], dtype = torch.float32)
torch.mm(n1,n2)
tensor([[ 22.,  30.],
        [ 76., 108.]])
a = np.arange(10).reshape(2,5)
t = torch.from_numpy(a)
t
tensor([[0, 1, 2, 3, 4],
        [5, 6, 7, 8, 9]], dtype=torch.int32)