Fastest way to calculate "cosine" metrics with scipy
<p>I am given a matrix of ones and zeros. I need to find 20 rows which have the highest cosine metrics towards 1 <code>specific</code> row in matrix:  </p>

<p>If I have 10 rows, and 5th is called <code>specific</code>, I want to choose the highest value between these:<br>
<code>cosine(1row,5row),cosine(2row,5row),...,cosine(8row,5row),cosine(9row,5row)</code></p>

<p>First, i tried to count metrics. 
This didn't work:</p>

<pre><code>A = ratings[:,100]
A = A.reshape(1,A.shape[0])
B = ratings.transpose()
similarity = -cosine(A,B)+1
A.shape = (1L, 71869L)
B.shape = (10000L, 71869L)
</code></pre>

<p>Error is: <code>Input vector should be 1-D.</code> I'd like to know, how to implement this aesthetically with no errors, but the most important - which solution will be the fastest? </p>

<p>In my opinion, the fastest way is not realized with help of <code>scipy</code>;
We just have to take all ones in <code>specific</code> row and look at these indices in all other rows. Those rows, which have the highest coincidence will have the highest matrix.  </p>

<p>Are there any faster ways?</p>

<p>The fastest way is to use matrix operations: <code>something like np.multipy(A,B)</code> </p>

python scipy cosine