Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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]
like image 888
Mary Pari Avatar asked Jul 20 '26 11:07

Mary Pari


1 Answers

try this:

c = b[np.any(b != a, axis=(1))]
print(c)
like image 123
Hozayfa El Rifai Avatar answered Jul 23 '26 00:07

Hozayfa El Rifai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!