1. 程式人生 > >pytorch之tensor學習

pytorch之tensor學習

import torch as t
a=t.randn(3,4)
print("原來的0:"+str(a))
print("1:"+str(a[2,3]))
print("2:"+str(a[0:1,:2]))
print("3:"+str(a[0,:2]))
print("4:"+str(a[0][2]))

輸出如下:

原來的0:
 1.4695 -0.2599 -0.4663 -0.7454
-0.1706  1.2879  0.2274 -0.8635
 0.4786  1.1047 -1.2737 -1.8188
[torch.FloatTensor of size 3x4]

1:-1.81884503365
2:
 1.4695 -0.2599
[torch.FloatTensor of size 1x2]

3:
 1.4695
-0.2599
[torch.FloatTensor of size 2]

4:-0.466291189194

不明白a[0]明明是第一行為什麼會寫成列