Mati Malik - 10 months ago 32

Python Question

I have this array

`scale=np.array([-3,0,2,4,7,10,12])`

And this matrix

`matrix=np.array([[17, 10, 10],`

[10, 12, 12],

[ 7, 7, 4],

[-3, 11, 2]])

Now i want to know the indices of the rows in matrix which doesn't contain any of the elements in scale. The output should be:

`array([0,3])`

I've tried with np.where, np.all and np.any without solving the problem.

Do you have a simple solution to this?

Answer

You are rather looking for:

```
np.where(~np.in1d(matrix, scale).reshape(matrix.shape).all(axis=1))
#(array([0, 3], dtype=int64),)
```