title: Scipy cosine similarity vs sklearn cosine similarity
body: <p>I noticed that both <code>scipy</code> and <code>sklearn</code> have a cosine similarity/cosine distance functions. I wanted to test the speed for each on pairs of vectors:</p>
  <pre class="lang-py prettyprint-override"><code>setup1 = &quot;import numpy as np; arrs1 = [np.random.rand(400) for _ in range(60)];arrs2 = [np.random.rand(400) for _ in range(60)]&quot;
  setup2 = &quot;import numpy as np; arrs1 = [np.random.rand(400) for _ in range(60)];arrs2 = [np.random.rand(400) for _ in range(60)]&quot;
  
  import1 = &quot;from sklearn.metrics.pairwise import cosine_similarity&quot;
  stmt1 = &quot;[float(cosine_similarity(arr1.reshape(1,-1), arr2.reshape(1,-1))) for arr1, arr2 in zip(arrs1, arrs2)]&quot;
  
  import2 = &quot;from scipy.spatial.distance import cosine&quot;
  stmt2 = &quot;[float(1 - cosine(arr1, arr2)) for arr1, arr2 in zip(arrs1, arrs2)]&quot;
  
  import timeit
  print(&quot;sklearn: &quot;, timeit.timeit(stmt1, setup=import1 + &quot;;&quot; + setup1, number=1000))
  print(&quot;scipy:   &quot;, timeit.timeit(stmt2, setup=import2 + &quot;;&quot; + setup2, number=1000))
  </code></pre>
  <pre><code>sklearn:  11.072769448000145
  scipy:    1.9755544730005568
  </code></pre>
  <p><code>sklearn</code> runs almost 10 times slower than <code>scipy</code> (even if you remove the array reshape for the sklearn example and generate data that's already in the right shape). Why is one significantly slower than the other?</p>