Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >>> import numpy as np
- >>> d = 64 # dimension
- >>> nb = 10000 # database size
- >>> nq = 1 # nb of queries
- >>> np.random.seed(1234) # make reproducible
- >>> xb = np.random.random((nb, d)).astype('float32')
- >>> xb[:, 0] += np.arange(nb) / 1000.
- >>> xq = np.random.random((nq, d)).astype('float32')
- >>> xq[:, 0] += np.arange(nq) / 1000.
- >>>
- >>> import faiss # make faiss available
- >>> index = faiss.IndexFlat(d) # build the index
- >>> print index.is_trained
- True
- >>> index.add(xb) # add vectors to the index
- >>> print index.ntotal
- 10000
- >>>
- >>> lims, D, I = index.range_search(xq, 0.0000000000000000000004)
- >>> D
- array([ 18.48775864, 18.66941452, 18.37726593, ..., 22.67871475,
- 24.99220467, 22.61538315], dtype=float32)
- >>> I
- array([ 0, 1, 2, ..., 9997, 9998, 9999])
- >>> len(I)
- 10000
- >>> lims, D, I = index.range_search(xq, 20)
- >>> len(I)
- 5927
- >>> lims, D, I = index.range_search(xq, 200)
- >>> len(I)
- 0
- >>>
Add Comment
Please, Sign In to add comment