Assign values to pytorch tensor
Everytime when I try to initialize a pytorch tensor, I would like to use torch.zeros
:
1 | sum_each_bbox = torch.zeros(len(bbox),len(bbox[0])) |
But when I try to assign interger value to the tensor, like:
1 | sum_each_bbox[i,j] = sum(bbox[i][j]) |
The value will be different:
1 | tensor(16906704.) |
Instead, we should specify the data type to make it assigned correctly.
1 | sum_each_bbox = torch.zeros(len(bbox),len(bbox[0]),dtype=torch.int64) |