(self, verbosity=0, max_leaf_count=40)
return out.getvalue().strip()
Returns the summary of the dendrogram.

        The summary includes the number of leafs and branches, and also an
        ASCII art representation of the dendrogram unless it is too large.

        @param verbosity: determines whether the ASCII representation of the
          dendrogram should be printed. Zero verbosity prints only the number
          of leafs and branches.
        @param max_leaf_count: the maximal number of leafs to print in the
          ASCII representation. If the dendrogram has more leafs than this
          limit, the ASCII representation will not be printed even if the
          verbosity is larger than or equal to 1.
        @return: the summary of the dendrogram as a string.
Returns the summary of the dendrogram.
Returns the summary of the dendrogram .
def summary(self, verbosity=0, max_leaf_count=40):
        """Returns the summary of the dendrogram.

        The summary includes the number of leafs and branches, and also an
        ASCII art representation of the dendrogram unless it is too large.

        @param verbosity: determines whether the ASCII representation of the
          dendrogram should be printed. Zero verbosity prints only the number
          of leafs and branches.
        @param max_leaf_count: the maximal number of leafs to print in the
          ASCII representation. If the dendrogram has more leafs than this
          limit, the ASCII representation will not be printed even if the
          verbosity is larger than or equal to 1.
        @return: the summary of the dendrogram as a string.
        """
        out = StringIO()
        print(
            "Dendrogram, %d elements, %d merges"
            % (
                self._nitems,
                self._nmerges,
            ),
            file=out,
        )

        if self._nitems == 0 or verbosity < 1 or self._nitems > max_leaf_count:
            return out.getvalue().strip()

        print("", file=out)

        positions = [None] * self._nitems
        inorder = self._traverse_inorder()
        distance = 2
        level_distance = 2
        nextp = 0
        for idx, element in enumerate(inorder):
            positions[element] = nextp
            inorder[idx] = str(element)
            nextp += max(distance, len(inorder[idx]) + 1)

        width = max(positions) + 1

        # Print the nodes on the lowest level
        print((" " * (distance - 1)).join(inorder), file=out)
        midx = 0
        max_community_idx = self._nitems
        while midx < self._nmerges:
            char_array = [" "] * width
            for position in positions:
                if position >= 0:
                    char_array[position] = "|"
            char_str = "".join(char_array)
            for _ in range(level_distance - 1):
                print(char_str, file=out)  # Print the lines

            cidx_incr = 0
            while midx < self._nmerges:
                id1, id2 = self._merges[midx]
                if id1 >= max_community_idx or id2 >= max_community_idx:
                    break
                midx += 1

                pos1, pos2 = positions[id1], positions[id2]
                positions[id1], positions[id2] = -1, -1

                if pos1 > pos2:
                    pos1, pos2 = pos2, pos1
                positions.append((pos1 + pos2) // 2)

                dashes = "-" * (pos2 - pos1 - 1)
                char_array[pos1 : (pos2 + 1)] = "`%s'" % dashes

                cidx_incr += 1

            max_community_idx += cidx_incr

            print("".join(char_array), file=out)

        return out.getvalue().strip()
def summary ( self , verbosity = 0 , max_leaf_count = 40 ) : out = StringIO ( ) print ( "Dendrogram, %d elements, %d merges" % ( self . _nitems , self . _nmerges , ) , file = out , ) if self . _nitems == 0 or verbosity < 1 or self . _nitems > max_leaf_count : return out . getvalue ( ) . strip ( ) print ( "" , file = out ) positions = [ None ] * self . _nitems inorder = self . _traverse_inorder ( ) distance = 2 level_distance = 2 nextp = 0 for idx , element in enumerate ( inorder ) : positions [ element ] = nextp inorder [ idx ] = str ( element ) nextp += max ( distance , len ( inorder [ idx ] ) + 1 ) width = max ( positions ) + 1 # Print the nodes on the lowest level print ( ( " " * ( distance - 1 ) ) . join ( inorder ) , file = out ) midx = 0 max_community_idx = self . _nitems while midx < self . _nmerges : char_array = [ " " ] * width for position in positions : if position >= 0 : char_array [ position ] = "|" char_str = "" . join ( char_array ) for _ in range ( level_distance - 1 ) : print ( char_str , file = out ) # Print the lines cidx_incr = 0 while midx < self . _nmerges : id1 , id2 = self . _merges [ midx ] if id1 >= max_community_idx or id2 >= max_community_idx : break midx += 1 pos1 , pos2 = positions [ id1 ] , positions [ id2 ] positions [ id1 ] , positions [ id2 ] = - 1 , - 1 if pos1 > pos2 : pos1 , pos2 = pos2 , pos1 positions . append ( ( pos1 + pos2 ) // 2 ) dashes = "-" * ( pos2 - pos1 - 1 ) char_array [ pos1 : ( pos2 + 1 ) ] = "`%s'" % dashes cidx_incr += 1 max_community_idx += cidx_incr print ( "" . join ( char_array ) , file = out ) return out . getvalue ( ) . strip ( )