Tricks(四十二)—— 数据集分块

[X[k:k+mini_batch_size] for k in xrange(0, n, mini_batch_size)]
import random
X = [[random.randrange(0, 10) for _ in range(5)] for _ in xrange(20)]
random.shuffle(X)
            # 是否需要先打乱数据 
mini_batch_size, n = 5, len(X)
batches = [X[k:k+mini_batch_size] for k in xrange(0, n, mini_batch_size)]
            # 就本例而言,20/5 = 4,共分 4 个 batch

你可能感兴趣的:(Tricks(四十二)—— 数据集分块)