I have a list (let's call it all_my_arrays) that contains about 48,000 1D arrays. I'd like to know how many duplicate arrays are in this list, if any. However, I'd like to exclude empty arrays (because I have multiple empty arrays within the list and don't want those factored into my duplicate count). I tried this code below, but it is taking too long:
import numpy as np uniques=[] for arr in all_my_arrays: if not np.array_equal(np.array([]), arr): if not any(np.array_equal(arr, unique_arr) for unique_arr in uniques): uniques.append(arr) print(len(uniques)) #number of non-duplicates Is there a much quicker way to accomplish this?
all_my_arraysor a shallow copy of it. Then you only have to compare each array with the previous one to eliminate duplicates.array([1, 2, 3])the same asarray([3, 2, 1])?Truetonp.array_equal(array1, array2), which requires them to be the same length and that every elementarray1[i]andarray2[i]is the same for eachiwithin the range of length.