'Filtering a ndarray in numpy

I have a ndarray and I want to filter out a particular value of it. My array is:

arr = np.array([
   [1., 6., 1.],
   [1., 7., 0.],
   [1., 8., 0.],
   [3., 5., 1.],
   [5., 1., 1.],
   [5., 2., 2.],
   [6., 1., 1.],
   [6., 2., 2.],
   [6., 7., 3.],
   [6., 8., 0.]
])

I want to filter out [6., 1., 1.]. So I have tried:

arr[arr != [6., 1., 1.]]

and I got:

array([1., 6., 1., 7., 0., 1., 8., 0., 3., 5., 5., 5., 2., 2., 2., 2., 7.,
   3., 8., 0.])

which is not what I want (and also destroyed the previous structure of the array). I have also tried:

arr[arr[:] != [6., 1., 1.]]

but I got the same output as before.

P.S.: I know I can delete an element by its index, but I don't want to do that. I want to check for the particular element.

P.P.S.: For 1-d arrays my method works.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source