#NEWLINE# def top_topic_docs( self , doc_topic_matrix , topics = ( - 1 ) , top_n = 10 , weights = False ) : #NEWLINE# #INDENT# "\n        Get the top ``top_n`` docs by weight per topic in ``doc_topic_matrix``.\n\n        Args:\n            doc_topic_matrix (numpy.ndarray): document-topic matrix with shape\n                (n_docs, n_topics), the result of calling\n                :func:`get_doc_topic_matrix() <textacy.topic_modeling.get_doc_topic_matrix>`\n            topics (seq(int) or int, optional): topic(s) for which to return top docs;\n                if -1, all topics' docs are returned\n            top_n (int, optional): number of top docs to return per topic\n            weights (bool, optional): if True, docs are returned with their corresponding\n                (normalized) topic weights; otherwise, docs are returned without weights\n\n        Yields:\n            tuple(int, tuple(int)) or tuple(int, tuple(int, float)):\n                next tuple corresponding to a topic; the first element is the topic's\n                index; if ``weights`` is False, the second element is a tuple of ints\n                representing the top ``top_n`` related docs; otherwise, the second\n                is a tuple of (int, float) pairs representing the top ``top_n``\n                related docs and their associated weights wrt the topic; for example::\n\n                    >>> list(TopicModel.top_doc_terms(dtm, topics=(0, 1), top_n=2, weights=False))\n                    [(0, (4, 2)), (1, (1, 3))]\n                    >>> list(TopicModel.top_doc_terms(dtm, topics=0, top_n=2, weights=True))\n                    [(0, ((4, 0.3217), (2, 0.2154)))]\n        " #NEWLINE# if ( topics == ( - 1 ) ) : #NEWLINE# #INDENT# topics = range ( self . n_topics ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( topics , int ) : #NEWLINE# #INDENT# topics = ( topics , ) #NEWLINE# #UNINDENT# #UNINDENT# for topic_idx in topics : #NEWLINE# #INDENT# top_doc_idxs = np . argsort ( doc_topic_matrix [ : , topic_idx ] ) [ : ( ( - top_n ) - 1 ) : ( - 1 ) ] #NEWLINE# if ( weights is False ) : #NEWLINE# #INDENT# ( yield ( topic_idx , tuple ( ( doc_idx for doc_idx in top_doc_idxs ) ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ( yield ( topic_idx , tuple ( ( ( doc_idx , doc_topic_matrix [ ( doc_idx , topic_idx ) ] ) for doc_idx in top_doc_idxs ) ) ) )