TypeError: unhashable type: 'numpy.ndarray'
The problem is that you're passing a list of numpy arrays to the mode function.
It requires either a single list of values, or a single numpy array with values (basically any single container will do, but seemingly not a list of arrays).

This is because it must make a hash map of some kind in order to determine the most common occurences, hence the mode.  It is unable to hash a list of arrays.

One solution would be to simple index the value out of each array (which then means mode gets a list of integers). Just changing the main line to:

max_voting_pred = np.append(max_voting_pred, mode([a[i][0], b[i][0]]))


Let me know if that doesn't fix things.



If you want something that is perhaps easier than fixing your orignal code, try using the mode function from the scipy module: scipy.stats.mode.

This version allows you to pass the whole array and simply specify an axis along which to compute the mode. Given you have the full vectors of predictions from both models:


Combine both arrays to be the two columns of one single (200, 2) matrix

results = np.concatenate((y_pred, vgg16_y_pred), axis=1)



Now you can perform the mode on that matrix across the single rows, but all in one single operation (no need for a loop):

max_votes = scipy.stats.mode(results, axis=1)


The results contain two things.


the mode values for each row
the counts of that mode within that row.


So to get the results you want (that would match your original max_voters_pred, you must take the first element from max_votes:

max_voters_pred = max_votes[0]