facebookresearch / pysparnn

Approximate Nearest Neighbor Search for Sparse Data in Python!
Other
915 stars 146 forks source link

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

Open moinnadeem opened 6 years ago

moinnadeem commented 6 years ago

Hi!

I setup the index with the following parameters:

cp = ci.MultiClusterIndex(X, df)
cp.search(X, k=100)

X is a sparse array of dimension (128405, 75897).

Here's a copy of the traceback. Any advice? Thanks!

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-18-58e590b5ec59> in <module>()
----> 1 cp.search(X, k=100)

/home/moinnadeem/.virtualenvs/quizlet/lib/python2.7/site-packages/pysparnn/cluster_index.pyc in search(self, features, k, k_clusters, return_distance, num_indexes)
    474             ret.append(
    475                 _filter_distance(
--> 476                     _k_best(_filter_unique(r), k),
    477                     return_distance
    478                 )

/home/moinnadeem/.virtualenvs/quizlet/lib/python2.7/site-packages/pysparnn/cluster_index.pyc in _filter_unique(tuple_list)
     40     ret = []
     41     for distance, value in tuple_list:
---> 42         if not value in added:
     43             ret.append((distance, value))
     44             added.add(value)

TypeError: unhashable type: 'numpy.ndarray'
spencebeecher commented 6 years ago

Thanks for the question! What is the type of X? The second argument works best when the type is a list - instead of passing 'df' i would pass the index of df 'df.Index.values'. If this doesn't work - could you share a simple version of your code with me? Thanks!