问题
我有一个大的(> 500e6行)数据集,我已经放入pytables数据库.
让我们说第一列是ID,第二列是每个ID的计数器.每个ID计数器组合必须是唯一的.我想要找到的500e6行中有一个非唯一的行.
作为首发,我做过这样的事情:
index1 = db.cols.id.create_index()
index2 = db.cols.counts.create_index()
for row in db:
query = '(id == %d) & (counts == %d)' % (row['id'], row['counts'])
result = th.readWhere(query)
if len(result) > 1:
print row
Run Code Online (Sandbox Code Playgroud)
我承认这是一种蛮力方法.有关改进的建议吗?
更新
目前的暴力运行时间为8421分钟.
解决方案 感谢大家的投入.我设法使用以下方法将运行时间降低到2364.7秒:
ex = tb.Expr('(x * 65536) + y', uservars = {"x":th.cols.id, "y":th.cols.counts})
ex = tb.Expr(expr)
ex.setOutput(th.cols.hash)
ex.eval()
indexrows = th.cols.hash.create_csindex(filters=filters)
ref = None
dups = []
for row in th.itersorted(sortby=th.cols.hash):
if row['hash'] == ref:
dups.append(row['hash'] )
ref = row['hash']
print("ids: …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用matplotlib重新创建上述绘图样式.
原始数据存储在2D numpy数组中,其中快轴是时间.
绘制线条很容易.我正在努力有效地获得阴影区域.
我目前的尝试看起来像:
import numpy as np
from matplotlib import collections
import matplotlib.pyplot as pylab
#make some oscillating data
panel = np.meshgrid(np.arange(1501), np.arange(284))[0]
panel = np.sin(panel)
#generate coordinate vectors.
panel[:,-1] = np.nan #lazy prevents polygon wrapping
x = panel.ravel()
y = np.meshgrid(np.arange(1501), np.arange(284))[0].ravel()
#find indexes of each zero crossing
zero_crossings = np.where(np.diff(np.signbit(x)))[0]+1
#calculate scalars used to shift "traces" to plotting corrdinates
trace_centers = np.linspace(1,284, panel.shape[-2]).reshape(-1,1)
gain = 0.5 #scale traces
#shift traces to plotting coordinates
x = ((panel*gain)+trace_centers).ravel() …
Run Code Online (Sandbox Code Playgroud)