(cluster, level=None, height=None, condition=None)
return T[cluster]
Prune the clustering instance ``cluster``.

    :param Tree cluster: Cluster root node to prune.
    :param int level: If not `None` prune all clusters deeper then `level`.
    :param float height:
        If not `None` prune all clusters with height lower then `height`.
    :param function condition:
        If not `None condition must be a `Tree -> bool` function
        evaluating to `True` if the cluster should be pruned.

    .. note::
        At least one `level`, `height` or `condition` argument needs to
        be supplied.
Prune the clustering instance ``cluster``.
Prune the clustering instance cluster .
def prune(cluster, level=None, height=None, condition=None):
    """
    Prune the clustering instance ``cluster``.

    :param Tree cluster: Cluster root node to prune.
    :param int level: If not `None` prune all clusters deeper then `level`.
    :param float height:
        If not `None` prune all clusters with height lower then `height`.
    :param function condition:
        If not `None condition must be a `Tree -> bool` function
        evaluating to `True` if the cluster should be pruned.

    .. note::
        At least one `level`, `height` or `condition` argument needs to
        be supplied.

    """
    if not any(arg is not None for arg in [level, height, condition]):
        raise ValueError("At least one pruning argument must be supplied")

    level_check = height_check = condition_check = lambda cl: False

    if level is not None:
        cluster_depth = cluster_depths(cluster)
        level_check = lambda cl: cluster_depth[cl] >= level

    if height is not None:
        height_check = lambda cl: cl.value.height <= height

    if condition is not None:
        condition_check = condition

    def check_all(cl):
        return level_check(cl) or height_check(cl) or condition_check(cl)

    T = {}

    for node in postorder(cluster):
        if check_all(node):
            if node.is_leaf:
                T[node] = node
            else:
                T[node] = Tree(node.value, ())
        else:
            T[node] = Tree(node.value,
                           tuple(T[ch] for ch in node.branches))
    return T[cluster]
def prune ( cluster , level = None , height = None , condition = None ) : if not any ( arg is not None for arg in [ level , height , condition ] ) : raise ValueError ( "At least one pruning argument must be supplied" ) level_check = height_check = condition_check = lambda cl : False if level is not None : cluster_depth = cluster_depths ( cluster ) level_check = lambda cl : cluster_depth [ cl ] >= level if height is not None : height_check = lambda cl : cl . value . height <= height if condition is not None : condition_check = condition def check_all ( cl ) : return level_check ( cl ) or height_check ( cl ) or condition_check ( cl ) T = { } for node in postorder ( cluster ) : if check_all ( node ) : if node . is_leaf : T [ node ] = node else : T [ node ] = Tree ( node . value , ( ) ) else : T [ node ] = Tree ( node . value , tuple ( T [ ch ] for ch in node . branches ) ) return T [ cluster ]