Python Tensorflow:np数组的下一批函数

Python Tensorflow:np数组的下一批函数,python,machine-learning,tensorflow,Python,Machine Learning,Tensorflow,我有火车数据 xTrain = numpy.asarray([100, 1, 5, 6 ...]) yTrain = numpy.asarray([200, 2, 10, 12 ...]) 如何定义next_batchsize方法以从列车数据中获取随机元素的大小编号。您可以将其用作下一批函数: def batch_data(source, target, batch_size): # Shuffle data shuffle_indices = np.random.permuta

我有火车数据

xTrain = numpy.asarray([100, 1, 5, 6 ...])
yTrain = numpy.asarray([200, 2, 10, 12 ...])
如何定义next_batchsize方法以从列车数据中获取随机元素的大小编号。

您可以将其用作下一批函数:

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)

ValueError:当我为batch\u size指定的值大于size if source时,太多的值无法解压缩。是否希望batch\u size>source size?。为什么?那么它就不再是一批了。你能编辑你的问题吗?你到底想要什么功能?