title: Transform a set of numbers in numpy so that each number gets converted into a number of other numbers which are less than it
body: <p>Consider a set of numbers:</p>
  
  <pre><code>In [8]: import numpy as np
  
  In [9]: x = np.array([np.random.random() for i in range(10)])
  
  In [10]: x
  Out[10]: 
  array([ 0.62594394,  0.03255799,  0.7768568 ,  0.03050498,  0.01951657,
          0.04767246,  0.68038553,  0.60036203,  0.3617409 ,  0.80294355])
  </code></pre>
  
  <p>Now I want to transform this set into another set <code>y</code> in the following way: for every element <code>i</code> in <code>x</code>, the corresponding element <code>j</code> in <code>y</code> would be the number of other elements in <code>x</code> which are less than <code>i</code>. For example, the above given <code>x</code> would look like:</p>
  
  <pre><code>In [25]: y
  Out[25]: array([ 6.,  2.,  8.,  1.,  0.,  3.,  7.,  5.,  4.,  9.])
  </code></pre>
  
  <p>Now, I can do this using simple python loops:</p>
  
  <pre><code>In [16]: for i in range(len(x)):
      ...:     tot = 0
      ...:     for j in range(len(x)):
      ...:         if x[i] &gt; x[j]: tot += 1
      ...:     y[i] = int(tot)
  </code></pre>
  
  <p>However, when length of <code>x</code> is very large, the code becomes extremely slow. I was wondering if any numpy magic can be brought to rescue. For example, if I had to filter all the elements less than <code>0.5</code>, I would have simply used a Boolean masking:</p>
  
  <pre><code>In [19]: z = x[x &lt; 0.5]
  
  In [20]: z
  Out[20]: array([ 0.03255799,  0.03050498,  0.01951657,  0.04767246,  0.3617409 ])
  </code></pre>
  
  <p>Can something like this be used so that the same thing could be achieved much faster?</p>