You could always do just:

a=[1,2,3]
b=['a','b']
c=[1,2,3,4]
d=[1,2,3]

a==b    #returns False
a==c    #returns False
a==d    #returns True
Answer from skajfes on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-compare-two-numpy-arrays
How to compare two NumPy arrays? - GeeksforGeeks
September 19, 2025 - DSA Python · Data Science · NumPy · Pandas · Practice · Django · Flask · Last Updated : 19 Sep, 2025 · Sometimes you need to check if two arrays are same or compare their values. NumPy provides multiple ways to do this from simple equality checks to element-wise comparisons.
🌐
Note.nkmk.me
note.nkmk.me › home › python › numpy
NumPy: Compare two arrays element-wise | note.nkmk.me
February 3, 2024 - In NumPy, to compare two arrays (ndarray) element-wise, use comparison operators such as > or ==, which return a Boolean ndarray. You can also compare an array to a scalar value. Additionally, NumPy o ...
🌐
Delft Stack
delftstack.com › home › howto › numpy › python compare arrays
How to Compare Two Arrays in Python | Delft Stack
February 2, 2024 - The below example code demonstrates how to use the == operator and numpy.all() method to compare the two arrays in Python.
🌐
w3resource
w3resource.com › python-exercises › numpy › python-numpy-exercise-28.php
NumPy: Compare two given arrays - w3resource
August 29, 2025 - # Importing the NumPy library with an alias 'np' import numpy as np # Creating NumPy arrays 'a' and 'b' a = np.array([1, 2]) b = np.array([4, 5]) # Displaying the arrays 'a' and 'b' print("Array a: ", a) print("Array b: ", b) # Comparing elements of 'a' and 'b' for greater than operation print("a > b") print(np.greater(a, b)) # Comparing elements of 'a' and 'b' for greater than or equal operation print("a >= b") print(np.greater_equal(a, b)) # Comparing elements of 'a' and 'b' for less than operation print("a < b") print(np.less(a, b)) # Comparing elements of 'a' and 'b' for less than or equal operation print("a <= b") print(np.less_equal(a, b))
🌐
Reddit
reddit.com › r/python › compare two array and extract the elements that are not same.
r/Python on Reddit: Compare two array and extract the elements that are not same.
February 1, 2023 -

In the below code, in which the variable ar consist mostly of [[255. 255. 255.]...] but there are very few element that has different values. I want to extract those values and their index separately. In the below, I presented the function code and results, dtypes are same, things are done correctly but it fails. Need some help!

    def get_colors(ar):
        # ar shape 128 x128 x3.
        shape = ar.shape
        # Convert to n x 3.
        ar = ar.reshape(scipy.product(shape[:2]), shape[2]).astype(float)
        print("ar : ", ar)
        # identify white colors
        mm = np.array([225, 225, 225]).astype(float)
        print("mm : ", mm)
        # to match the size of ar, we use tile
        mm_broadcasted = np.tile(mm, (ar.shape[0], 1))
        print("mm_broadcasted : ", mm_broadcasted)
        kkk = (ar != mm_broadcasted)
        print("kkk:",kkk)
        not_matching = ar[(ar != mm_broadcasted).all(axis=1)]
        indices = np.argwhere((ar != mm_broadcasted).all(axis=1)).ravel()
        print("not_matching:", not_matching)
        print("indices:", indices)

--------------------------------------------------------
Here are the result:

ar :  [[255. 255. 255.]
 [255. 255. 255.]
 [255. 255. 255.]
 ...
 [255. 255. 255.]
 [255. 255. 255.]
 [255. 255. 255.]]
mm :  [225. 225. 225.]
mm_broadcasted :  [[225. 225. 225.]
 [225. 225. 225.]
 [225. 225. 225.]
 ...
 [225. 225. 225.]
 [225. 225. 225.]
 [225. 225. 225.]]
kkk: [[ True  True  True]
 [ True  True  True]
 [ True  True  True]
 ...
 [ True  True  True]
 [ True  True  True]
 [ True  True  True]]
not_matching: [[255. 255. 255.]
 [255. 255. 255.]
 [255. 255. 255.]
 ...
 [255. 255. 255.]
 [255. 255. 255.]
 [255. 255. 255.]]
indices: [    0     1     2 ... 16381 16382 16383]

🌐
TutorialsPoint
tutorialspoint.com › python-program-to-check-if-two-arrays-are-equal
Python Program to Check if two arrays are equal
May 5, 2023 - import numpy as np arr1 = [1, 2, 3, 4, 5] arr2 = [1, 2, 3, 4, 5] arr3 = [5, 4, 3, 2, 1] # Element-wise comparison print("arr1 == arr2:", np.array_equal(arr1, arr2)) print("arr1 == arr3:", np.array_equal(arr1, arr3)) # Using == operator with all() result = (np.array(arr1) == np.array(arr2)).all() print("Using == with all():", result) arr1 == arr2: True arr1 == arr3: False Using == with all(): True · Sort both arrays and compare element by element to check if they contain the same elements ?
Find elsewhere
🌐
Quora
quora.com › How-do-you-find-if-two-arrays-are-equal-in-Python-programming
How to find if two arrays are equal in Python programming - Quora
Answer (1 of 3): Technically Python doesn’t have builtin support for arrays. There is an array module in the standard libraries (you can import it). But almost no on uses that. Mostly you can use Python lists as arrays; for most applications, involving only thousands or even hundreds of ...
🌐
w3resource
w3resource.com › python-exercises › numpy › basic › numpy-basic-exercise-44.php
NumPy: Test two arrays are equal (element wise) or not - w3resource
August 28, 2025 - The task requires leveraging NumPy's array comparison functionalities, such as "np.array_equal", which efficiently checks whether the elements in the two arrays match. By comparing the arrays element-wise, the program provides a boolean result indicating whether the arrays are equal or not, facilitating array-based data validation and verification tasks. Sample Solution : Python Code : # Importing the NumPy library with an alias 'np' import numpy as np # Creating NumPy arrays 'nums1' and 'nums2' with floating-point values nums1 = np.array([0.5, 1.5, 0.2]) nums2 = np.array([0.4999999999, 1.5000
🌐
GitHub
bic-berkeley.github.io › psych-214-fall-2016 › comparing_arrays.html
Comparing arrays — Functional MRI methods
Python assumes that True == 1 and False == 0 for this test of non-zero: >>> np.all([True, True, True]) True · >>> np.all([1, 2, 0]) False >>> np.all([True, False, True]) False · To ask whether all the elements in two arrays are equal, we can pass the result of the element-wise comparison to np.all: >>> np.all(arr1 == arr2) False ·
🌐
ArrayDiff
arraydiff.com › home › guides › how to compare two arrays in python
How to Compare Two Arrays in Python | ArrayDiff
August 15, 2026 - The practical rule follows directly: if order does not matter and the lists are large, sort or key them first and then compare positionally. That converts a quadratic problem into an O(n log n) sort plus a linear pass, which is the same reason left_by_id above beats a nested loop. Use Python List Diff when you need a full visual explanation instead of a boolean or a pair of sets.
🌐
TestMu AI Community
community.testmuai.com › ask a question
Compare Arrays in Python - Ask a Question - TestMu AI Community
January 20, 2025 - How can I compare arrays in Python? I have two strings: date = "Thu Sep 16 13:14:15 CDT 2010" sdate = "Thu Sep 16 14:14:15 CDT 2010" I split these strings into lists using: dateArr = date.split() sdateArr = sdate.spl…
🌐
YouTube
youtube.com › watch
2022: Intro to Python - Lab 18 - Comparing elements from two arrays - YouTube
AboutPressCopyrightContact usCreatorsAdvertiseDevelopersTermsPrivacyPolicy & SafetyHow YouTube worksTest new featuresNFL Sunday Ticket · © 2024 Google LLC
Published: October 23, 2022
Views: 111
🌐
Finxter
blog.finxter.com › home › learn python blog › 5 best ways to check if two python arrays are equal
5 Best Ways to Check If Two Python Arrays are Equal - Be on the Right Side of Change
February 26, 2024 - Using zip(), elements from the two arrays are paired, and the generator expression provides a comparison for each pair.
🌐
Medium
medium.com › unhandled-code › python-compare-two-arrays-get-the-differences-3a85364bef54
Python : Compare two arrays and get the differences | by Unhandled Perfection | Unhandled —Dev | Medium
February 9, 2018 - Python : Compare two arrays and get the differences arr1 = ['A', 'B', 'C', 'D', 'E'] arr2 = ['A', 'C', 'E'] # Get items in arr2 not in arr1 # output: [] list(set(arr2) - set(arr1)) # Get items in …
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.array_equal.html
numpy.array_equal — NumPy v2.5 Manual
Returns True if two arrays are element-wise equal within a tolerance. ... Returns True if input arrays are shape consistent and all elements equal. ... Try it in your browser! ... When equal_nan is True, complex values with nan components are considered equal if either the real or the imaginary ...