Skip to content

Instantly share code, notes, and snippets.

@hccho2
Last active November 29, 2020 01:31
Show Gist options
  • Save hccho2/ca1453a269d9336a02db926c603da590 to your computer and use it in GitHub Desktop.
Save hccho2/ca1453a269d9336a02db926c603da590 to your computer and use it in GitHub Desktop.
torch data
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)
@hccho2
Copy link
Author

hccho2 commented Nov 29, 2020

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment