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

ValueError: dimension mismatch, When using space coo matrix #38

Closed kharazi closed 8 years ago

kharazi commented 8 years ago

Hi there, I have this error when updating nearpy to new version,

    neighbours = nearpy_engine.neighbours(vector)
  File "/home/vahid/dev/mirad/backend/venv/local/lib/python2.7/site-packages/nearpy/engine.py", line 153, in neighbours
    nv = v / np.linalg.norm(v)
  File "/home/vahid/dev/mirad/backend/venv/local/lib/python2.7/site-packages/numpy/linalg/linalg.py", line 2126, in norm
    sqnorm = dot(x, x)
  File "/home/vahid/dev/mirad/backend/venv/local/lib/python2.7/site-packages/scipy/sparse/base.py", line 317, in __mul__
    raise ValueError('dimension mismatch')
ValueError: dimension mismatch

my vector is:

    basic_vector = vectorizer.transform(
        ['some text'])
    vector = basic_vector.transpose().tocoo()

and vectorizer is a sklearn hashing vectrozier (n_features=2**18). np.linalg.norm will dot(v, v) and since v is an sparce matrix this error occurs.

pixelogik commented 8 years ago

Thx. Will check soon.

kharazi commented 8 years ago

It's ok in your last commit. Release new version.