check if any values overlap in numpy array

Solutions on MaxInterview for check if any values overlap in numpy array by the best coders in the world

showing results for - "check if any values overlap in numpy array"
Alois
15 Jan 2021
1import numpy as np
2array_1 = np.array(((1, 2, 3), (4, 5, 6), (7, 8, 9)))
3array_2 = np.array(((3, 1, 2), (5, 4, 6), (7, 9, 8)))
4#In this example, array_2 does have some of the same elements(i.e. the 6s and 7s are in the same place)
5#This means that when we check if any of their elements are the same, we will get True.
6print(np.any(array_1 == array_2))
7#output is True
8print(np.all(array_1 == array_2))
9#output is False