Created
July 17, 2019 23:50
-
-
Save Hanrui-Wang/4b5a8d997a806957b951bd230fc9aaa3 to your computer and use it in GitHub Desktop.
difference between torch.Tensor and torch.from_numpy()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = np.arange(10) | |
ft = torch.Tensor(a) # same as torch.FloatTensor | |
it = torch.from_numpy(a) | |
a.dtype # == dtype('int64') | |
ft.dtype # == torch.float32 | |
it.dtype # == torch.int64 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I see that the above code is a typo herein code. because when you not defined the dtype in np.arrange(10). default takes to int32.
hence the output is incorrectly written as below.
a.dtype # == dtype('int64')
ft.dtype # == torch.float32
it.dtype # == torch.int64
the correct output is:
a.dtype # == dtype('int32')
ft.dtype # == torch.int32
it.dtype # == torch.int32
Please correct me if I'm wrong.
please see below image