view raw
Mati Malik Mati Malik - 1 year ago 41
Python Question

Check if matrix contains valid elements

I have this array


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:


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

Do you have a simple solution to this?


You are rather looking for:

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