brainstorm/tools.py
def split(*args, **kwargs):
    """
    Split numpy arrays into several parts according to a ratio.

    Args:
        *args (numpy.ndarray):
            arrays to be split.
        ratios (iterable[float]):
            ratios of sizes for the splits. Defaults to (9, 1)

    Returns:
        list of list of arrays. Eg for 2 splits of 3 arrays A, B, and C you'd
        get [(A1, B1, C1), (A2, B2, C2)].

    """
    N = args[0].shape[1]
    ratios = kwargs.get('ratios', (9, 1))
    normalized_ratios = np.array(ratios) / np.sum(ratios)
    split_idxs = np.round(np.cumsum(normalized_ratios) * N).astype(np.int)
    split_idxs = np.hstack([[0], split_idxs])
    all_splits = []
    for start, stop in zip(split_idxs[:-1], split_idxs[1:]):
        all_splits.append([None if A is None else A[:, start:stop]
                           for A in args])
    return all_splits

    Split numpy arrays into several parts according to a ratio.

    Args:
        *args (numpy.ndarray):
            arrays to be split.
        ratios (iterable[float]):
            ratios of sizes for the splits. Defaults to (9, 1)

    Returns:
        list of list of arrays. Eg for 2 splits of 3 arrays A, B, and C you'd
        get [(A1, B1, C1), (A2, B2, C2)].

    
Split numpy arrays into several parts according to a ratio.
Split numpy arrays into several parts according to a ratio .
def split(*args, **kwargs):
    N = args[0].shape[1]
    ratios = kwargs.get('ratios', (9, 1))
    normalized_ratios = np.array(ratios) / np.sum(ratios)
    split_idxs = np.round(np.cumsum(normalized_ratios) * N).astype(np.int)
    split_idxs = np.hstack([[0], split_idxs])
    all_splits = []
    for start, stop in zip(split_idxs[:-1], split_idxs[1:]):
        all_splits.append([None if A is None else A[:, start:stop]
                           for A in args])
    return all_splits
def split ( * args , ** kwargs ) : N = args [ 0 ] . shape [ 1 ] ratios = kwargs . get ( 'ratios' , ( 9 , 1 ) ) normalized_ratios = np . array ( ratios ) / np . sum ( ratios ) split_idxs = np . round ( np . cumsum ( normalized_ratios ) * N ) . astype ( np . int ) split_idxs = np . hstack ( [ [ 0 ] , split_idxs ] ) all_splits = [ ] for start , stop in zip ( split_idxs [ : - 1 ] , split_idxs [ 1 : ] ) : all_splits . append ( [ None if A is None else A [ : , start : stop ] for A in args ] ) return all_splits
Split numpy arrays into several parts according to a ratio.
Split numpy arrays into several parts according to a ratio .
"""
    Split numpy arrays into several parts according to a ratio.

    Args:
        *args (numpy.ndarray):
            arrays to be split.
        ratios (iterable[float]):
            ratios of sizes for the splits. Defaults to (9, 1)

    Returns:
        list of list of arrays. Eg for 2 splits of 3 arrays A, B, and C you'd
        get [(A1, B1, C1), (A2, B2, C2)].

    """
list of list of arrays.
list of list of arrays .
*args
arrays to be split.
arrays to be split .
ratios
ratios of sizes for the splits. Defaults to (9, 1)
ratios of sizes for the splits . Defaults to ( 9 1 )