代码拉取完成,页面将自动刷新
import random
import time
from neighborpy.engine import Engine
import numpy as np
import pandas as pd
DIM = 128
dname = 'test'
engine = Engine(dim=DIM)
engine.create_db(dname)
POINTS = 100_000
reader = open('data.txt', 'r')
fx1 = list(map(float, reader.readline().rstrip('\n').strip('[').strip(']').split(',')))
fx2 = list(map(float, reader.readline().rstrip('\n').strip('[').strip(']').split(',')))
dot = round(random.uniform(0.3, 0.7),3)
key = random.randint(0, POINTS)
matrix = {}
for i in range(POINTS):
if i == key:
matrix['k_' + str(i)] = np.array(fx1)
else:
v = np.random.randn(DIM)
matrix['k_' + str(i)] = v
c1 = time.clock()
df = pd.DataFrame.from_dict(matrix, orient='index')
c2 = time.clock()
print('build DataFrame from %d items, clock: %0.6f' % (POINTS, (c2 - c1)))
print(df.shape[0])
k2 = random.randint(0, POINTS)
c1 = time.clock()
df.drop(index='k_' + str(k2), inplace=True)
c2 = time.clock()
print('delete item from %d items DataFrame, clock: %0.6f' % (POINTS, (c2 - c1)))
print(df.shape[0])
c1 = time.clock()
engine.add_items(dname, vs=matrix)
c2 = time.clock()
print('add %d items clock: %0.6f' % (POINTS, (c2 - c1)))
# c1 = time.clock()
# for i in range(0, 5):
# p = int(POINTS*round(random.uniform(0.01, 0.99),3))
# rk = 'k_' + str(p)
# engine.delete_item(dname, rk)
# print('delete %s' % rk)
# c2 = time.clock()
#
# print('delete item clock: %0.6f' % (c2 - c1))
times = 100
c1 = time.clock()
for i in range(0, times):
ind = engine.query_item(dname, np.array(fx2), 10)
c2 = time.clock()
print('query, clock: %0.6f' % ((c2 - c1)/times))
print('key: K_%s, result: %s' % (key, ind))
# dic = {}
# dic2 = {'key':'t1', 'val':'v1'}
# dic['t1'] = np.array([[1,2,3],[2,3,4,],[3,4,5]])
# dic['t2'] = np.array([[4,5,6],[5,6,7]])
# dic['t3'] = np.array([[6,7,8]])
#
# dic3 = np.append(dic['t1'], dic['t2'], axis=0)
#
# data = [[1,2,3,4],[4,5,6,7,8]]
# #dic['data'] = data
# dic['dic'] = dic2
# print(dic)
# dic7 = np.array(data)
# print(dic7)
# l2 = {
# 'key': 123,
# 'Value': 231
# }
# l3 = []
#
# try:
# print(l2['ttt'])
# except BaseException as err:
# print(err)
# print(dic3)
# print(np.size(dic3, 0))
# print(np.random.randn(128))
# matrix = np.ones((100000, 128))
# start = time.clock()
# tree = BallTree(matrix, leaf_size=2000)
# end = time.clock()
# print('build tree, clock %0.6f' % (end - start))
# example1()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。