toolbox/nt/database/iterator.py
def recursive_transform(func, dict_list_val, list2array=False):
    """
    Applies a function func to all leaf values in a dict or list or directly to
    a value. The hierarchy of dict_list_val is inherited. Lists are stacked
    to numpy arrays. This function can e.g. be used to recursively apply a
    transformation (e.g. audioread) to all audio paths in an example dict
    (see top of this file).
    :param func: a transformation function to be applied to the leaf values
    :param dict_list_val: dict list or value
    :param args: args for func
    :param kwargs: kwargs for func
    :param list2array:
    :return: dict, list or value with transformed elements
    """
    if isinstance(dict_list_val, dict):
        # Recursively call itself
        return {key: recursive_transform(func, val, list2array)
                for key, val in dict_list_val.items()}
    if isinstance(dict_list_val, (list, tuple)):
        # Recursively call itself
        l = type(dict_list_val)(
            [recursive_transform(func, val, list2array)
             for val in dict_list_val]
        )
        if list2array:
            return np.array(l)
        return l
    else:
        # applies function to a leaf value which is not a dict or list
        return func(dict_list_val)

    Applies a function func to all leaf values in a dict or list or directly to
    a value. The hierarchy of dict_list_val is inherited. Lists are stacked
    to numpy arrays. This function can e.g. be used to recursively apply a
    transformation (e.g. audioread) to all audio paths in an example dict
    (see top of this file).
    :param func: a transformation function to be applied to the leaf values
    :param dict_list_val: dict list or value
    :param args: args for func
    :param kwargs: kwargs for func
    :param list2array:
    :return: dict, list or value with transformed elements
    
Applies a function func to all leaf values in a dict or list or directly to
a value. The hierarchy of dict_list_val is inherited. Lists are stacked
to numpy arrays.
Applies a function func to all leaf values in a dict or list or directly to a value . The hierarchy of dict_list_val is inherited . Lists are stacked to numpy arrays .
def recursive_transform(func, dict_list_val, list2array=False):
    if isinstance(dict_list_val, dict):
        return {key: recursive_transform(func, val, list2array)
                for key, val in dict_list_val.items()}
    if isinstance(dict_list_val, (list, tuple)):
        l = type(dict_list_val)(
            [recursive_transform(func, val, list2array)
             for val in dict_list_val]
        )
        if list2array:
            return np.array(l)
        return l
    else:
        return func(dict_list_val)
def recursive_transform ( func , dict_list_val , list2array = False ) : if isinstance ( dict_list_val , dict ) : return { key : recursive_transform ( func , val , list2array ) for key , val in dict_list_val . items ( ) } if isinstance ( dict_list_val , ( list , tuple ) ) : l = type ( dict_list_val ) ( [ recursive_transform ( func , val , list2array ) for val in dict_list_val ] ) if list2array : return np . array ( l ) return l else : return func ( dict_list_val )
Applies a function func to all leaf values in a dict or list or directly to
a value.
Applies a function func to all leaf values in a dict or list or directly to a value .
"""
    Applies a function func to all leaf values in a dict or list or directly to
    a value. The hierarchy of dict_list_val is inherited. Lists are stacked
    to numpy arrays. This function can e.g. be used to recursively apply a
    transformation (e.g. audioread) to all audio paths in an example dict
    (see top of this file).
    :param func: a transformation function to be applied to the leaf values
    :param dict_list_val: dict list or value
    :param args: args for func
    :param kwargs: kwargs for func
    :param list2array:
    :return: dict, list or value with transformed elements
    """ # Recursively call itself # Recursively call itself # applies function to a leaf value which is not a dict or list
dict, list or value with transformed elements
dict list or value with transformed elements
func
a transformation function to be applied to the leaf values
a transformation function to be applied to the leaf values
dict_list_val
dict list or value
dict list or value
list2array
None
args
args for func
args for func
kwargs
kwargs for func
kwargs for func