import copy


def ApplyFunToRadii(fiber_bundles, fun):
    """
    Applies function to fibers radii

    Parameters
    ----------
    fiber_bundles : [[(,4)-array, ...]]
        list of fibers
    fun : function

    Returns
    -------
    res : [[(,4)-array, ...]]
        fiber_bundles
    """

    fiber_bundles = copy.deepcopy(fiber_bundles)
    for j, fb in enumerate(fiber_bundles):
        for i, _ in enumerate(fb):
            fiber_bundles[j][i][:, -1] = fun(fiber_bundles[j][i][:, -1])
    return fiber_bundles