def leaders(Z, T):
Z = np.asarray(Z, order='<STR_LIT:c>')<EOL>T = np.asarray(T, order='<STR_LIT:c>')<EOL>if type(T) != np.ndarray or T.dtype != '<STR_LIT:i>':<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>is_valid_linkage(Z, throw=True, name='<STR_LIT>')<EOL>if len(T) != Z.shape[<NUM_LIT:0>] + <NUM_LIT:1>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>Cl = np.unique(T)<EOL>kk = len(Cl)<EOL>L = np.zeros((kk,), dtype='<STR_LIT:i>')<EOL>M = np.zeros((kk,), dtype='<STR_LIT:i>')<EOL>n = Z.shape[<NUM_LIT:0>] + <NUM_LIT:1><EOL>[Z, T] = _copy_arrays_if_base_present([Z, T])<EOL>s = _hierarchy.leaders(Z, T, L, M, int(kk), int(n))<EOL>if s >= <NUM_LIT:0>:<EOL><INDENT>raise ValueError(('<STR_LIT>'<EOL>'<STR_LIT>') % s)<EOL><DEDENT>return (L, M)<EOL>
Returns the root nodes in a hierarchical clustering.

Returns the root nodes in a hierarchical clustering corresponding
to a cut defined by a flat cluster assignment vector ``T``. See
the ``fcluster`` function for more information on the format of ``T``.

For each flat cluster :math:`j` of the :math:`k` flat clusters
represented in the n-sized flat cluster assignment vector ``T``,
this function finds the lowest cluster node :math:`i` in the linkage
tree Z such that:

  * leaf descendents belong only to flat cluster j
    (i.e. ``T[p]==j`` for all :math:`p` in :math:`S(i)` where
    :math:`S(i)` is the set of leaf ids of leaf nodes descendent
    with cluster node :math:`i`)

  * there does not exist a leaf that is not descendent with
    :math:`i` that also belongs to cluster :math:`j`
    (i.e. ``T[q]!=j`` for all :math:`q` not in :math:`S(i)`).  If
    this condition is violated, ``T`` is not a valid cluster
    assignment vector, and an exception will be thrown.

Parameters
----------
Z : ndarray
    The hierarchical clustering encoded as a matrix. See
    ``linkage`` for more information.
T : ndarray
    The flat cluster assignment vector.

Returns
-------
L : ndarray
    The leader linkage node id's stored as a k-element 1-D array
    where ``k`` is the number of flat clusters found in ``T``.

    ``L[j]=i`` is the linkage cluster node id that is the
    leader of flat cluster with id M[j].  If ``i < n``, ``i``
    corresponds to an original observation, otherwise it
    corresponds to a non-singleton cluster.

    For example: if ``L[3]=2`` and ``M[3]=8``, the flat cluster with
    id 8's leader is linkage node 2.
M : ndarray
    The leader linkage node id's stored as a k-element 1-D array where
    ``k`` is the number of flat clusters found in ``T``. This allows the
    set of flat cluster ids to be any arbitrary set of ``k`` integers.