pixelogik / NearPy

Python framework for fast (approximated) nearest neighbour search in large, high-dimensional data sets using different locality-sensitive hashes.
MIT License
759 stars 152 forks source link

TypeError: unhashable type: 'numpy.ndarray' #60

Open Zehaos opened 7 years ago

Zehaos commented 7 years ago

Hi, I'm trying NearPy, and I got some error. Below is some code and error message.

import scipy.io as sio

mat_file = sio.loadmat("C:\\Users\\RA2\\Desktop\\Workspaces\\LightenedCNN_A_lfw.mat")
fea = mat_file["features"]
labels = mat_file["labels_original"]
img_path = mat_file["image_path"]

from nearpy import Engine
from nearpy.hashes import RandomBinaryProjections

# Dimension of our vector space
dimension = 256

n_d = 10
rbp1 = RandomBinaryProjections('rbp', n_d)

# Create engine with pipeline configuration
engine = Engine(dimension, lshashes=[rbp1])

for v, i in zip(fea[1:,:], range(1, len(fea)+1)):
    engine.store_vector(v, img_path[i])

query = fea[0]

# Get nearest neighbours
N = engine.neighbours(query)
File "C:\Users\RA2\Anaconda3\lib\site-packages\nearpy\filters\uniquefilter.py", line 51, in filter_vectors
    unique_dict[v[1]] = v

TypeError: unhashable type: 'numpy.ndarray'

The code crash when n_d is below 15. Is this a bug?

Thanks Zehao Shi