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>If you want to do it the numpy way,</p>

<pre><code>import numpy as np

A = np.array([[1, 1, 1,], [1, 1, 2], [1, 1, 3], [1, 1, 4]])
B = np.array([[0, 0, 0], [1, 0, 2], [1, 0, 3], [1, 0, 4], [1, 1, 0], [1, 1, 1], [1, 1, 4]])
A_rows = A.view([('', A.dtype)] * A.shape[1])
B_rows = B.view([('', B.dtype)] * B.shape[1])

diff_array = np.setdiff1d(A_rows, B_rows).view(A.dtype).reshape(-1, A.shape[1])
</code></pre>

<p>As @Rahul suggested, for a non numpy easy solution,</p>

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

python arrays numpy