Learn practical skills, build real-world projects, and advance your career
import torch
#function1 stack
a = torch.tensor(1.)
b = torch.tensor(5.)
c = torch.tensor(5.)

print(f"a: {a}, b: {b}, c:{c}")
a.dtype

d = [a,b,c]
print("d",d)
a: 1.0, b: 5.0, c:5.0 d [tensor(1.), tensor(5.), tensor(5.)]

torch.stack is used to concatenates a sequence of tensors along a new dimension

stk = torch.stack(d)
print(stk) # as we can see the sequence of tensors are changed to tensors
tensor([1., 5., 5.])