Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
误差';列表未定义';在python中附加到相同的声明列表时_Python_Python 3.x_List_For Loop - Fatal编程技术网

误差';列表未定义';在python中附加到相同的声明列表时

误差';列表未定义';在python中附加到相同的声明列表时,python,python-3.x,list,for-loop,Python,Python 3.x,List,For Loop,我定义了一个函数,在该函数中,我将附加到一个空列表。 相同的代码附在下面。 但当我在下一个函数中调用该列表时,错误显示: 未定义名称“序列集大小” 我的代码是: test_percent=0.3 # as an example batch_size = 10 # as an example def get_LSTM_train_size(datain, batch_size, test_percent): number_of_samples = datain.shape[0]

我定义了一个函数,在该函数中,我将附加到一个空列表。 相同的代码附在下面。 但当我在下一个函数中调用该列表时,错误显示: 未定义名称“序列集大小”

我的代码是:

test_percent=0.3 # as an example
batch_size = 10 # as an example

def get_LSTM_train_size(datain, batch_size, test_percent):
   
    number_of_samples = datain.shape[0]
    print("# Shape of the input dataframe",number_of_samples)
    number_of_samples *= 1 - test_percent
    
    train_set_sizes = []
    
    for size in range(int(number_of_samples) - 100,int(number_of_samples)): 
        mod=size%batch_size
        if (mod == 0):
            train_set_sizes.append([size])
            print(size)
    return train_set_sizes, max(train_set_sizes)
list.append()
函数在现有列表上工作

您可以在调用该函数之前声明一个空列表

train_set_sizes = []

您已经在当前函数中声明了列表,因此不能在其他函数中使用它,除非将其设置为全局或返回整个列表。
另外,如果您共享完整的代码,帮助会更容易。

您是否声明了
列车设置大小列表?对不起,我不明白您的问题。您可以共享您的全部代码吗?对不起,我忘了提到我也创建了一个空列表。我也会修改我的原始问题。尽管声明了一个空列表,我仍然得到了相同的错误。请给出完整的代码。以及全部错误。我们需要确切地知道错误发生在哪里