Deleting sub array from a larger multi dimensional array without changing the dimensions

Viewed 40

Having arrays a, and b I would like to get the array c which excludes a from b.

a=np.array([8,14])

[ 8 14]

b=np.array([[3,2],[8,10],[8,14],[17,65]])

[[ 3  2]
 [ 8 10]
 [ 8 14]
 [17 65]]

The desired c is :

print(c)
[[ 3  2]
 [ 8 10]
 [17 65]]

numpy delete does not seem to work as expected because it takes the index as input for removing the section of array.

np.delete(b, a)
[ 3  2  8 10 8 14 17 65]
1 Answers

try this:

c = b[np.any(b != a, axis=(1))]
print(c)
Related