Guest User

Untitled

a guest
Feb 21st, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. >>> import numpy as np
  2. >>> d = 64 # dimension
  3. >>> nb = 10000 # database size
  4. >>> nq = 1 # nb of queries
  5. >>> np.random.seed(1234) # make reproducible
  6. >>> xb = np.random.random((nb, d)).astype('float32')
  7. >>> xb[:, 0] += np.arange(nb) / 1000.
  8. >>> xq = np.random.random((nq, d)).astype('float32')
  9. >>> xq[:, 0] += np.arange(nq) / 1000.
  10. >>>
  11. >>> import faiss # make faiss available
  12. >>> index = faiss.IndexFlat(d) # build the index
  13. >>> print index.is_trained
  14. True
  15. >>> index.add(xb) # add vectors to the index
  16. >>> print index.ntotal
  17. 10000
  18. >>>
  19. >>> lims, D, I = index.range_search(xq, 0.0000000000000000000004)
  20. >>> D
  21. array([ 18.48775864, 18.66941452, 18.37726593, ..., 22.67871475,
  22. 24.99220467, 22.61538315], dtype=float32)
  23. >>> I
  24. array([ 0, 1, 2, ..., 9997, 9998, 9999])
  25. >>> len(I)
  26. 10000
  27. >>> lims, D, I = index.range_search(xq, 20)
  28. >>> len(I)
  29. 5927
  30. >>> lims, D, I = index.range_search(xq, 200)
  31. >>> len(I)
  32. 0
  33. >>>
Add Comment
Please, Sign In to add comment