(y, graph, root, copy=True)
return y_
Compute the full ancestor set for y, where y is in binary multi-label format,
    e.g. as a matrix of 0-1.

    Each row will be processed and filled in with 1s in indexes corresponding
    to the ancestor nodes of those already marked with 1 in that row,
    based on the given class hierarchy graph.

    Parameters
    ----------
    y : array-like, shape = [n_samples, n_classes].
        multi-class targets, corresponding to graph node integer ids.

    graph : the class hierarchy graph, given as a `networkx.DiGraph` instance

    root : identifier of the (stub) root node of hierarchy

    copy : bool, whether to update the y array in-place. defaults to True.

    Returns
    -------
    y_ : array-like, shape = [n_samples, n_classes].
        multi-class targets, corresponding to graph node integer ids with
        all ancestors of existing labels in matrix filled in, per row.
Compute the full ancestor set for y, where y is in binary multi-label format,
    e.g. as a matrix of 0-1.
Compute the full ancestor set for y where y is in binary multi - label format e . g . as a matrix of 0 - 1 .
def fill_ancestors(y, graph, root, copy=True):
    """
    Compute the full ancestor set for y, where y is in binary multi-label format,
    e.g. as a matrix of 0-1.

    Each row will be processed and filled in with 1s in indexes corresponding
    to the ancestor nodes of those already marked with 1 in that row,
    based on the given class hierarchy graph.

    Parameters
    ----------
    y : array-like, shape = [n_samples, n_classes].
        multi-class targets, corresponding to graph node integer ids.

    graph : the class hierarchy graph, given as a `networkx.DiGraph` instance

    root : identifier of the (stub) root node of hierarchy

    copy : bool, whether to update the y array in-place. defaults to True.

    Returns
    -------
    y_ : array-like, shape = [n_samples, n_classes].
        multi-class targets, corresponding to graph node integer ids with
        all ancestors of existing labels in matrix filled in, per row.

    """
    y_ = y.copy() if copy else y
    paths = all_pairs_shortest_path_length(graph.reverse(copy=False))
    for target, distances in paths:
        if target == root:
            # Our stub root node, can skip
            continue
        ix_rows = np.where(y[:, target] > 0)[0]
        # all ancestors, except the last one which would be the root node
        ancestors = list(distances.keys())[:-1]
        y_[tuple(np.meshgrid(ix_rows, ancestors))] = 1
    graph.reverse(copy=False)
    return y_
def fill_ancestors ( y , graph , root , copy = True ) : y_ = y . copy ( ) if copy else y paths = all_pairs_shortest_path_length ( graph . reverse ( copy = False ) ) for target , distances in paths : if target == root : # Our stub root node, can skip continue ix_rows = np . where ( y [ : , target ] > 0 ) [ 0 ] # all ancestors, except the last one which would be the root node ancestors = list ( distances . keys ( ) ) [ : - 1 ] y_ [ tuple ( np . meshgrid ( ix_rows , ancestors ) ) ] = 1 graph . reverse ( copy = False ) return y_