Computational_Biolgy/Fout_2017/extra.py
def loader(num_samples, b_size, shuffle=True):
    """Generate bacthes of random indices to behave as a dataloader.

    Parameters
    ----------
    num_samples : int
        Number of samples.
    b_size : int
        Batch size.
    shuffle : bool, True by deffault
        Permute batches if True, keep order otherwise.
    Returns
    -------
    batches : list
        A list of lists, each of size b_size. The last batch may
        contain exaclty b_size samples or the remaining number of samples.
    """
    if shuffle:
        rng = np.random.default_rng()
        idx = rng.permutation(num_samples).tolist()
    else:
        idx = list(range(num_samples))
    num_batches = num_samples // b_size
    remaining = num_samples % b_size
    batches = [idx[b * b_size: (b + 1)*b_size] for b in range(num_batches)]
    batches.append(idx[-remaining:]) if remaining != 0 else batches
    return batches
Generate bacthes of random indices to behave as a dataloader.

    Parameters
    ----------
    num_samples : int
        Number of samples.
    b_size : int
        Batch size.
    shuffle : bool, True by deffault
        Permute batches if True, keep order otherwise.
    Returns
    -------
    batches : list
        A list of lists, each of size b_size. The last batch may
        contain exaclty b_size samples or the remaining number of samples.
    
Generate bacthes of random indices to behave as a dataloader.
Parameters

num_samples : int
Number of samples.
b_size : int
Batch size.
shuffle : bool, True by deffault
Permute batches if True, keep order otherwise.
Returns

batches : list
A list of lists, each of size b_size. The last batch may
contain exaclty b_size samples or the remaining number of samples.
Generate bacthes of random indices to behave as a dataloader . Parameters num_samples : int Number of samples . b_size : int Batch size . shuffle : bool True by deffault Permute batches if True keep order otherwise . Returns batches : list A list of lists each of size b_size . The last batch may contain exaclty b_size samples or the remaining number of samples .
def loader(num_samples, b_size, shuffle=True):
    if shuffle:
        rng = np.random.default_rng()
        idx = rng.permutation(num_samples).tolist()
    else:
        idx = list(range(num_samples))
    num_batches = num_samples // b_size
    remaining = num_samples % b_size
    batches = [idx[b * b_size: (b + 1)*b_size] for b in range(num_batches)]
    batches.append(idx[-remaining:]) if remaining != 0 else batches
    return batches
def loader ( num_samples , b_size , shuffle = True ) : if shuffle : rng = np . random . default_rng ( ) idx = rng . permutation ( num_samples ) . tolist ( ) else : idx = list ( range ( num_samples ) ) num_batches = num_samples // b_size remaining = num_samples % b_size batches = [ idx [ b * b_size : ( b + 1 ) * b_size ] for b in range ( num_batches ) ] batches . append ( idx [ - remaining : ] ) if remaining != 0 else batches return batches
Generate bacthes of random indices to behave as a dataloader.
Generate bacthes of random indices to behave as a dataloader .
"""Generate bacthes of random indices to behave as a dataloader.

    Parameters
    ----------
    num_samples : int
        Number of samples.
    b_size : int
        Batch size.
    shuffle : bool, True by deffault
        Permute batches if True, keep order otherwise.
    Returns
    -------
    batches : list
        A list of lists, each of size b_size. The last batch may
        contain exaclty b_size samples or the remaining number of samples.
    """
num_samples
b_size
shuffle