Skip to content

Instantly share code, notes, and snippets.

@mandubian
Created July 21, 2020 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mandubian/0f0894b6ac72812a39d682423a151811 to your computer and use it in GitHub Desktop.
Save mandubian/0f0894b6ac72812a39d682423a151811 to your computer and use it in GitHub Desktop.
>>> import torch
# a Float tensor
>>> a = torch.tensor([[0, 0], [1, 1], [2, 2]], dtype=torch.float)
>>> a
tensor([[0., 0.],
[1., 1.],
[2., 2.]])
# a Long tensor
>>> b = torch.tensor([[3], [4], [5]], dtype=torch.long)
>>> b
tensor([[3],
[4],
[5]])
# Torch on float vs long tensors => WTF?
>>> torch.cat([a, b], dim=1)
tensor([[0.0000e+00, 0.0000e+00, 4.2039e-45],
[1.0000e+00, 1.0000e+00, 0.0000e+00],
[2.0000e+00, 2.0000e+00, 5.6052e-45]])
# Torch on float vs float tensors => WTF?
>>> torch.cat([a, b.float()], dim=1)
tensor([[0., 0., 3.],
[1., 1., 4.],
[2., 2., 5.]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment