Files
FoodClassifier/demo/看一下向量的数量.py
T

21 lines
383 B
Python

import faiss
import numpy as np
# 建一个 2 维向量的 L2 索引
index = faiss.IndexFlatL2(2)
print(index.ntotal) # 初始是 0
# 插入 5 个向量
data = np.random.rand(5, 2).astype("float32")
index.add(data)
print(index.ntotal) # 现在是 5
# 再插入 3 个
more_data = np.random.rand(3, 2).astype("float32")
index.add(more_data)
print(index.ntotal) # 现在是 8