我的火车数据为
xTrain = numpy.asarray([100, 1, 5, 6 ...])
yTrain = numpy.asarray([200, 2, 10, 12 ...])
如何定义 next_batch(size) 方法以从训练数据中获取随机元素的 size 个数。
您可以使用它作为您的next batch
功能:
def batch_data(source, target, batch_size):
# Shuffle data
shuffle_indices = np.random.permutation(np.arange(len(target)))
source = source[shuffle_indices]
target = target[shuffle_indices]
for batch_i in range(0, len(source)//batch_size):
start_i = batch_i * batch_size
source_batch = source[start_i:start_i + batch_size]
target_batch = target[start_i:start_i + batch_size]
yield np.array(source_batch), np.array(target_batch)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)