小编Anc*_*ami的帖子

如何在python中使用spotify的annoy库?

我想知道 annoy 库是如何工作的。我从 github 得到了这个测试代码,但我是编码新手,所以我很难理解 .

from annoy import AnnoyIndex
import random
f = 40

t = AnnoyIndex(f, 'angular')  #Length of item vector that will be indexed
for i in range(1000):
    v = [random.gauss(0, 1) for z in range(f)]
    t.add_item(i, v)

t.build(10) # 10 trees
t.save('test.ann')

u = AnnoyIndex(f, 'angular')
u.load('test.ann') # super fast, will just mmap the file
print(u.get_nns_by_item(0, 1000)) # will find the 1000 nearest neighbors
Run Code Online (Sandbox Code Playgroud)

computer-vision python-3.x annoy

12
推荐指数
1
解决办法
5423
查看次数

标签 统计

annoy ×1

computer-vision ×1

python-3.x ×1