简体   繁体   English

如何使用theano标量在python中切片列表?

[英]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.

相关问题 如何使用Python中的索引列表获取列表切片? - How can I get the list slice using a list of indexes in Python? 如何通过广播切片来切片图像? 错误:在python中“只有整数标量数组可以转换为标量索引”? - How to slice image by broadcasting slices? Error: 'only integer scalar arrays can be converted to a scalar index' in python? 为什么我可以在python中更新列表切片但不更新字符串切片? - Why can I update a list slice but not a string slice in python? 我可以使用排序对列表的一部分进行排序吗 - can i sort a slice of a list using sorted 我怎样才能将此代码(theano)转换为简单的python lign - how can I convert this code (theano) to a simple python lign 如何在 Python 中反转列表切片? 在每一步我们反转列表的间隔并输出整个列表 - How can i reverse slice of list in Python? At each step we invert an interval of the list and output the entire list Python 切片操作方法,我知道 Python 切片,但如何使用内置切片对象呢? - Python slice how-to, I know the Python slice but how can I use built-in slice object for it? 在theano中使用张量标量变量索引列表 - indexing a list with a tensor scalar variable in theano 在 Python 中,如何根据列表中的项目对列表进行切片? - In Python how do I slice a list based on an item in the list? 我可以使用变量在 Python 中分割我的列表吗? - Can I use a variable to slice my list in Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM