我有一个数据跟踪,我想在一个二维数组,取决于距离。我能想到的唯一方法是计算到空间中所有点(x,y)的距离,并替换数组中的值,以匹配我的datatrace“移动”的距离。我可以让它工作,但需要60秒来计算数字。我知道避免for循环可以更快,但我想不出来。我如何做下面的代码做的,但更快
我试过使用np.put,但它没有达到我想要的效果,因为它要求索引。我不知道指数!我到处找了,但找不到解决办法
跟踪像这样:datatrace, almost everywhere zero and a few peaks in the middle而我要查找的图像像这样:elliptic rings where the datatrace peaks
# correlation is my datatrace and is sample_time*sample_rate long,
# but interesting stuff is happening in the middle of the trace.
samples = np.linspace(0, room_size[1], sample_time*sample_rate)
xx, yy = np.meshgrid(samples, samples)
t = distance(point1, (xx, yy), point2)
z=np.zeros(t.shape)
for samp in samples[np.min(t):np.max(t)]:
z[t==samp] = correlation[samp]
代码的工作方式和它应该的一样,但是我怎样才能更快呢
目前没有回答
相关问题 更多 >
编程相关推荐