0

I have the following matrix in numpy [[1 0 0 1 1 1], [1 0 0 0 1 0], [1 1 0 0 1 0], [0 1 0 1 1 1], [0 0 0 1 0 1]] and I want to check if the array [1 0 0 0 1 0] is in the matrix. I try to use

if 1-array in 2-D array:
  print('True')

but I have an error DeprecationWarning: elementwise comparison failed; this will raise an error in the future.

Ch3steR
  • 20,090
  • 4
  • 28
  • 58
  • You do not have an `error` - you have a warning. Code will work now, but in future versions might throw an error. – Patrick Artner May 24 '20 at 10:03
  • Does this answer your question? [testing whether a Numpy array contains a given row](https://stackoverflow.com/questions/14766194/testing-whether-a-numpy-array-contains-a-given-row) – Joe May 24 '20 at 11:20
  • https://stackoverflow.com/questions/33217660/checking-if-a-numpy-array-contains-another-array?noredirect=1&lq=1 – Joe May 24 '20 at 11:20
  • https://stackoverflow.com/questions/51031140/check-whether-2d-array-contains-a-specific-1d-array-in-numpy?noredirect=1&lq=1 – Joe May 24 '20 at 11:21
  • https://stackoverflow.com/questions/14766194/testing-whether-a-numpy-array-contains-a-given-row – Joe May 24 '20 at 11:21

1 Answers1

0

If I run

import numpy as np
arr_2d = np.array([[1, 0, 0, 1, 1, 1], 
                   [1, 0, 0, 0, 1, 0], 
                   [1, 1, 0, 0, 1, 0], 
                   [0, 1, 0, 1, 1, 1], 
                   [0, 0, 0, 1, 0, 1]])
arr_1d = np.array([1, 0, 0, 0, 1, 0])
print(arr_1d in arr_2d)

It returns True without warnings.

I would suggest posting the code you used to get to those arrays, so we can see if there's something wrong with them.

Carlo Alberto
  • 187
  • 10