Last active
November 29, 2020 01:31
-
-
Save hccho2/ca1453a269d9336a02db926c603da590 to your computer and use it in GitHub Desktop.
torch data
This file contains 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
import torch | |
import numpy as np | |
x = torch.Tensor([[100],[200]]) | |
y = init.uniform_(x,-5,5) # x의 값을 변경 --> return 되는 것은 alias | |
w = x.detach() | |
print(x,y,w) # x,y는 같은 객체 | |
a = np.array([[2],[1.]]) | |
case = 2 | |
if case==1: | |
x.data = torch.from_numpy(a) # x,y는 변하고, w는 변하지 않는다. | |
elif case == 2: | |
x[...] = torch.from_numpy(a) # x,y,w 모두 변한다. | |
print(x,y,w) |
Author
hccho2
commented
Nov 29, 2020
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment