import sys
import faiss
import numpy as np
d = 64
nb = 100
nq = 10
np.random.seed(1234)
xb = np.random.random((nb,d)).astype('float32')
print xb[:2]
xb[:, 0] += np.arange(nb).astype('float32') / 1000
#sys.exit()
print xb[:2]
xq = np.random.random((nq, d)).astype('float32')
xq[:, 0] += np.arange(nq).astype('float32') / 1000
index = faiss.IndexFlatL2(d) # buid the index
print (index.is_trained),"@@"
index.add(xb)
print index.ntotal # 加入了多少行数据
k = 4
D,I = index.search(xb[:5],k)
print "IIIIIIIIIIII"
print I
print "ddddddddd"
print D
print "#########"
index = faiss.IndexFlatIP(d)
index.add(xb)
k = 4
D,I = index.search(xb[:5],k)
print I
print "ddddddddd"
print D
标签:index,记录,xb,random,np,使用,print,faiss
From: https://www.cnblogs.com/yunhgu/p/17528670.html