data = tensor:narrow(dim, index, size)
–表示取出tensor中第dim维上索引从index开始到index+size-1的所有元素存放在data中
>>> import torch
>>> a = torch.rand(5,6)
>>> a
tensor([[0.9737, 0.5571, 0.3870, 0.1706, 0.2312, 0.8780],
[0.3136, 0.9588, 0.2739, 0.5845, 0.8543, 0.0935],
[0.5776, 0.9492, 0.0968, 0.6593, 0.7120, 0.5754],
[0.5512, 0.1732, 0.3472, 0.8737, 0.9488, 0.2409],
[0.5602, 0.5082, 0.5949, 0.7618, 0.3155, 0.0606]])
>>> b = a.narrow(0,2,3)
>>> b
tensor([[0.5776, 0.9492, 0.0968, 0.6593, 0.7120, 0.5754],
[0.5512, 0.1732, 0.3472, 0.8737, 0.9488, 0.2409],
[0.5602, 0.5082, 0.5949, 0.7618, 0.3155, 0.0606]])
>>> c = a.narrow(1,2,3)
>>> c
tensor([[0.3870, 0.1706, 0.2312],
[0.2739, 0.5845, 0.8543],
[0.0968, 0.6593, 0.7120],
[0.3472, 0.8737, 0.9488],
[0.5949, 0.7618, 0.3155]])