shuffled_data = data [shuffle_indices] IndexError:数组的索引太多了

时间:2017-06-27 11:52:31

标签: python-3.x machine-learning neural-network sentiment-analysis

def batch_iter(data,batch_size,num_epochs):

"""
Generates a batch iterator for a dataset.
"""
data = np.array(data)
data_size = len(str(data))
num_batches_per_epoch = int(len(str(data))/batch_size) + 1
for epoch in range(num_epochs):
    # Shuffle the data at each epoch
    shuffle_indices = np.random.permutation(np.arange(data_size))
    shuffled_data = data[shuffle_indices]
    for batch_num in range(num_batches_per_epoch):
        start_index = batch_num * batch_size
        end_index = min((batch_num + 1) * batch_size, data_size)
        yield shuffled_data[start_index:end_index]

错误 数据处理OK,创建网络......

追踪(最近一次呼叫最后一次):

文件“twitter-sentiment-cnn.py”,第299行,

test_batches = list(batch_iter(zip(x_test, y_test), FLAGS.batch_size, 1))

文件“/home/bizviz/Desktop/twitter-sentiment-cnn/data_helpers.py”,第183行,在batch_iter中

shuffled_data = data[shuffle_indices]

IndexError:数组的索引太多

我不明白为什么我得到这个错误,不是一维的,请帮我解决这个问题。

0 个答案:

没有答案