for tj, in tdense[ti,tjv nowdense is matrix of topics we can use the pdist function in scipy to compute all pairwise distances that iswith single function callwe compute all the values of sum((dense[tidense[tj])** )from scipy spatial import distance pairwise distance squareform(distance pdist(dense)now we employ one last little trickwe set the diagonal elements of the distance matrix to high value (it just needs to be larger than the other values in the matrix)largest pairwise max(for ti in range(len(topics))pairwise[ti,tilargest+ and we are donefor each documentwe can look up the closest element easilydef closest_to(doc_id)return pairwise[doc_idargmin(the previous code would not work if we had not set the diagonal elements to large valuethe function would always return the same element as it is almost similar to itself (except in the weird case where two elements have exactly the same topic distributionwhich is very rare unless they are exactly the samefor examplehere is the second document in the collection (the first document is very uninterestingas the system returns post stating that it is the most similar)fromgeb@cs pitt edu (gordon bankssubjectrerequest for information on "essential tremorand indrolin article sundar@ai mit edu writesessential tremor is progressive hereditary tremor that gets worse when the patient tries to use the effected member all limbsvocal cordsand head can be involved inderal is beta-blocker and is usually effective in diminishing the tremor alcohol and mysoline are also effectivebut alcohol is too toxic to use as treatment gordon banks jxp "skepticism is the chastity of the intellectand geb@cadre dsl pitt edu it is shameful to surrender it too soon if we ask for the most similar documentclosest_to( )we receive the following documentfromgeb@cs pitt edu (gordon banks