Torch
ph
links
iTorch
https://github.com/facebook/iTorch
ipython같이 쓸 수 있음.
etc
storage
Tensor is a particular way of viewing a Storage. storage로 접근하면 내부 배열에 순차적으로 접근 가능. matlab에서 2차원 이상 배열을 1차원배열 index로 접근하는 것과 동일.
x = torch.Tensor(4,5) s = x:storage() for i=1,s:size() do -- fill up the Storage s[i] = i end
apply
x:apply(function(x) return x end)
narrow
:narrow(dim, offset, length)
행렬의 slice를 가져옴. dim=1은 row, 2는 column, 3이상도 가능.(row가 먼저임에 주의)
offset=1이면 첫줄부터 가져옴. 즉 start index라고 보면 된다.
length는 해당 dimension의 vector몇개를 가져올지 지정. 즉 length=3이라고 해서 숫자 세개가 오는 것이 아니다. 5\(\times\)4 행렬에서 narrow(1,3,2)하면, 다음 색칠한 두줄을 반환한다.
0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 |
초기화
x = torch.Tensor(5):zero() x = torch.Tensor(5):fill(1) x:zero() -- creates a storage with 10 elements s = torch.Storage(10):fill(1) torch.Tensor({{1,2,3,4}, {5,6,7,8}})