Removing elements from an array that are in another array
<p>Say I have these 2D arrays A and B.</p>

<p>How can I remove elements from A that are in B.</p>

<pre><code>A=np.asarray([[1,1,1], [1,1,2], [1,1,3], [1,1,4]])
B=np.asarray([[0,0,0], [1,0,2], [1,0,3], [1,0,4], [1,1,0], [1,1,1], [1,1,4]])
#output = [[1,1,2], [1,1,3]]
</code></pre>

<hr>

<p>To be more precise, I would like to do something like this.</p>

<pre><code>data = some numpy array
label = some numpy array
A = np.argwhere(label==0) #[[1 1 1], [1 1 2], [1 1 3], [1 1 4]]
B = np.argwhere(data&gt;1.5) #[[0 0 0], [1 0 2], [1 0 3], [1 0 4], [1 1 0], [1 1 1], [1 1 4]]
out = np.argwhere(label==0 and data&gt;1.5) #[[1 1 2], [1 1 3]]
</code></pre>

<p>there is a easy solution with <a href="http://www.secnetix.de/olli/Python/list_comprehensions.hawk" rel="nofollow">list comprehension</a>,</p>

<pre><code>A = [i for i in A if i not in B]
</code></pre>

<p>Result</p>

<pre><code>[[1, 1, 2], [1, 1, 3]]
</code></pre>

<p>List comprehension it's not removing the elements from the array, It's just reassigning, </p>

<p>if you want to remove the elements use this method</p>

<pre><code>for i in B:
     if i in A:
     A.remove(i)
</code></pre>

python arrays numpy