[英]How can I slice a list in python using a theano scalar?
index = T.iscalar()
train_function = theano.function(inputs = [index], outputs = [cost_function], updates = updates,
givens = {
x: train_set[0][index * batch_size: (index + 1) * batch_size],
y: train_set[1][index * batch_size: (index + 1) * batch_size]
})
I am trying to follow a theano tutorial and trying to implement my own version of logistic regression. 我正在尝试遵循theano教程,并试图实现自己的逻辑回归版本。 I have created a function that takes an integer input as an input and trains the model. 我创建了一个函数,该函数将整数输入作为输入并训练模型。 train_set[0] is the entire matrix data, train_set[1] is the entire label data train_set [0]是整个矩阵数据,train_set [1]是整个标签数据
X and Y are subsets of matrix and label data respectively X和Y分别是矩阵和标签数据的子集
Since I am training batch wise, I need to remove batch samples from my data which I do using the index variable. 由于我正在按批次进行训练,因此需要使用index变量从数据中删除批次样本。
However I get the following error at this line of code 但是我在这行代码中收到以下错误
TypeError: slice indices must be integers or None or have an __index__ method
I have also tried 我也尝试过
index = lscalar()
Any suggestions ? 有什么建议么 ?
Figured it out. 弄清楚了。 Had to convert train_set[0] and test_set[0] into a theano array variable 必须将train_set [0]和test_set [0]转换为theano数组变量
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.