title: Python - remove elements from array
body: <p>I have an array called <code>a</code> and another array <code>b</code>. The array <code>a</code> is the main array where I store float data, and <code>b</code> is an array which contain some indexes belonging to <code>a</code>.</p>
  
  <p>Example:</p>
  
  <pre><code>a = [1.3, 1.7, 18.4, 56.2, 82.2, 18.1, 81.9, 56.9, -274.45]
  b = [0, 1, 2, 3, 4, 5, 6, 7]
  </code></pre>
  
  <p>In this example <code>b</code> contains indexes of <code>a</code> from <code>0</code> to <code>7</code>.</p>
  
  <p>What I'm trying to do in Python is to remove "duplicates", I mean to remove all indexes from <code>b</code> which have their similar value in <code>a</code>. For example, notice that there are pair <code>1.3</code> and <code>1.7</code>. Also, there are <code>18.4</code> and <code>18.1</code> etc. I want to find all these values and to write <code>-1</code> in all places in array <code>b</code> which has that value.</p>
  
  <p>Output should be the following:</p>
  
  <pre><code>b = [0, -1, 2, 3, 4, -1, -1, -1]
  </code></pre>
  
  <p>I think it is obvious what I am trying to achieve. Here index <code>1</code> is replaced with <code>-1</code> because in <code>a</code> it represents <code>1.7</code> which has "pair" <code>1.3</code>. Also, last 3 indexes represents <code>18.1</code>, <code>81.9</code> and <code>56.9</code> which also have their "pairs" before, so they are replaced with <code>-1</code>.</p>
  
  <p>Of course, I have a parameter <code>x</code> which represents how "similar" values are. So, here <code>x = 2</code> which mean that any 2 values which differ by <code>2</code> are similar.</p>
  
  <p><strong>What have I tried?</strong> I tried to use 2 nested for loops and a lot of unnecessary variables and my algorithm eats memory and performance. Is there an elegant <code>np</code>-ish way to achieve it?</p>