#NEWLINE# def _order_cluster_tree( Z ) : #NEWLINE# #INDENT# '\n    Returns clustering nodes in bottom-up order by distance.\n\n    Parameters\n    ----------\n    Z : scipy.cluster.linkage array\n        The linkage matrix.\n\n    Returns\n    -------\n    nodes : list\n        A list of ClusterNode objects.\n    ' #NEWLINE# q = deque ( ) #NEWLINE# tree = to_tree ( Z ) #NEWLINE# q . append ( tree ) #NEWLINE# nodes = [ ] #NEWLINE# while q : #NEWLINE# #INDENT# node = q . popleft ( ) #NEWLINE# if ( not node . is_leaf ( ) ) : #NEWLINE# #INDENT# bisect . insort_left ( nodes , node ) #NEWLINE# q . append ( node . get_right ( ) ) #NEWLINE# q . append ( node . get_left ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# return nodes