How to speed up numpy dot product with masks?
<p>I have 2 numpy arrays, <code>m1</code> and <code>m2</code> where <code>m1</code> is size (nx1) and <code>m2</code> is size (1xn) and I want to perform the multiplication <code>m1.dot(m2)</code> resulting in a matrix <code>m</code> of size (nxn)</p>

<p>I want to compute an approximate <code>m_approx</code>, by only using the highest k elements in <code>m1</code> and <code>m2</code> and making all other elements 0(all elements are positive). </p>

<p>I am trying to speed up the multiplication because the size <code>n</code> for me is large (~10k). I want to pick a small <code>k</code> say 100 and really speed up the multiplication. I have tried using numpy sparse matrix which does make the dot product lot faster but it is very slow to convert m1 and m2 into sparse vectors. How can I achieve this? I feel masks might be a way to achieve this but not sure how?</p>