in this def i get TypeError: unhashable type: ‘numpy.ndarray’ in line retrieved_indices_set = set(retrieved_indices)
def evaluate_retrieval(query_idx, retrieved_indices, relevant_indices):
# Convert each list element to a tuple
# Flatten the two-layer list and convert elements to tuples
arr = np.array(retrieved_indices) #retrieved_indices => 128 * 128 * 3
# Transpose the array and convert it to a list of tuples
retrieved_indices = tuple(list(map(tuple, np.vstack(arr.T))))
print(type(retrieved_indices))
# Create a set from the tuples
retrieved_indices_set = set(retrieved_indices)
relevant_retrieved = len(retrieved_indices_set.intersection(relevant_indices_set))
precision = relevant_retrieved / len(retrieved_indices_set) if len(retrieved_indices_set) > 0 else 0
return precision
I try this but didn't work
retrieved_indices_tuples = tuple(tuple(tuple(pixel) for pixel in row) for row in retrieved_indices)
New contributor
Erfan Hamidi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.