Mati Malik Mati Malik - 2 years ago 130
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?

Answer Source

You are rather looking for:

np.where(~np.in1d(matrix, scale).reshape(matrix.shape).all(axis=1))
#(array([0, 3], dtype=int64),)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download