yield: 较少内存消耗
#定义
def get_batch_data(self, data_x, data_y, batch):
#会丢弃最后少部分的数据
steps = len(data_y) // batch
for step in range(steps):
batch_x, batch_y = [], []
batch_x = data_x[step*batch:(step+1)*batch]
batch_y = data_y[step*batch:(step+1)*batch]
yield batch_x, batch_y
#调用
for x, y in get_batch_data(self, data_x, data_y, batch):
pritn(x, y)