All problems
Mini-Batch Indices
Problem
Generate mini-batch indices: call random.seed(seed), shuffle range(n), and cut the shuffled order into consecutive batches of size batch_size (the last batch may be shorter).
Return the list of batches; a non-positive batch_size returns [].
Hint
Shuffle once, then slice the shuffled order into fixed-size chunks.
Test cases
case 1
in: [5,2,42]
expected: [[3,1],[2,4],[0]]
case 2
in: [6,4,7]
expected: [[4,0,5,3],[1,2]]
case 3
in: [4,1,0]
expected: [[2],[0],[1],[3]]
case 4
in: [3,5,1]
expected: [[1,2,0]]
Starter codePython
import random
def mini_batch_indices(n, batch_size, seed):
# Your code here
pass4 test cases · run your code against them in the editor