Search notes:

Constructing a torch.Tensor with uppercase Tensor() vs lowercase tensor()

import torch

uc = torch.Tensor([ 1, 2, 3 ])
lc = torch.tensor([ 1, 2, 3 ])

#
#  Both, torch.Tensor(…) and torch.tensor() create
#  a torch.Tensor.
#
# print(type(lc))
# print(type(uc))

#
#  However, torch.tensor() takes into account the data types of the arguments
#  and creates a tensor with the corresponding data type (dtype).
#
print(lc.dtype) # torch.int64
print(uc.dtype) # torch.float32

print(lc)
#
# tensor([1, 2, 3])

print(uc)
#
# tensor([1., 2., 3.])

Index