这个 torch 语句的语法是如何工作的?

How does the syntax of this torch statement work?

我想了解这个特定的 torch 语句是如何工作的。

我指的是

的第 115 行

https://github.com/torch/tutorials/blob/master/2_supervised/1_data.lua#L115

该行显示为

trdata[{ {1,trainData.data:size(1)} }] = trainData.data

我正在阅读 torch 中的数据切片,我了解到

t4[{ {},1 }] 

表示您指的是张量 t4 的 "all the rows and 1st column"。

但是,在我上面打印的语句中,我们有一个 {} 里面另一个 { } 外面。这是什么意思?

我明白

trainData.data:size(1)

指的是trainData的batch size,大概就是图片的个数。

谢谢

这起到了缩小作用。请参考这些detailed explanations:

When you have double curly-braces, it returns a narrow of the tensor, and a narrowed tensor is always a tensor (even if it only has one element). With double curly-braces, you can specify a range in which the tensor will be narrowed, which is not possible with single curly-braces. For example, you can do ten[{{1,2},1}], which will be a 1D tensor of dimension 2, and if your do ten[{{1,2},{2}}] it will return a 2D tensor of size 2x1.

例如:

th> trsize = 10
th> trdata = torch.Tensor(trsize, 3, 32, 32)
th> subdata = trdata[{ {1, 5} }]
th> subdata:size()
  5
  3
 32
 32
[torch.LongStorage of size 4]