I tried to run the code below, but takes a long time, is there any way to improve this code? I tried with a lot of python functions but all look like are created to work with 1D arrays only, sorry for the code I am very new on this:
Function that returns an array that contains unique elements:
def get_unique_values(dataset):
uniqueimages=np.empty(dataset.shape, dtype=np.float32)
u=0
for i in range(dataset.shape[0]):
if (check_if_exists(dataset[i,:,:],uniqueimages)==0):
uniqueimages[u,:,:]=dataset[i,:,:]
u=u+1
return uniqueimages[0:u,:,:]
function that verifies if a given element is already in the array:
def check_if_exists( q,a ):
r=0
for i in range(a.shape[0]):
if np.array_equal(q,a[i,:,:]):
r=1
break
return r
then I run this giving a 3D array as input (shape= 2000,28,28):
vadu=get_unique_values(3Darray)
EDIT: this question was solved in the other linked question, thanks Divakar!