<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def gen_batch(data, batch_size, maxiter=np.inf, random_state=None):
 """ Create random batches for Stochastic gradients. Batch index generator for SGD that will yeild random batches for a a defined number of iterations, which can be infinite. This generator makes consecutive passes through the data, drawing without replacement on each pass. Parameters data : ndarray or sequence of ndarrays The data, can be a matrix X, (X,y) tuples etc batch_size : int number of data points in each batch. maxiter : int, optional The number of iterations random_state : int or RandomState, optional random seed Yields ------ ndarray or sequence : with each array length ``batch_size``, i.e. a subset of data. """

    perms = endless_permutations(_len_data(data), random_state)

    it = 0
    while it < maxiter:
        it += 1
        ind = np.array([next(perms) for _ in range(batch_size)])
        yield _split_data(data, ind)