python-3.x - scipy 的 numba,特别是 cdist
问题描述
我正在尝试加快两个点云之间的比较,我有一些代码需要一个小时才能完成。我已经把它屠杀了,并试图实现 numba。该代码与 scipy cdist 函数除外。这是我第一次使用 numba 测试,我哪里出错了?
from numba import jit
@jit(nopython=True)
def near_dist_top(T, B):
xi = [i[0] for i in T]
yi = [i[1] for i in T]
zi = [i[2] for i in T]
XB = B
insert_params = []
for i in range(len(T)):
XA = [T[i]]
disti = cdist(XA, XB, metric='euclidean').min()
insert_params.append((xi[i], yi[i], zi[i], disti))
# print("Top: " + str(i) + " of " + str(len(T)))
print(i)
return insert_params
print(XB)
@@@ 编辑@@@
T 和 B 都是坐标列表
(580992.507, 4275268.8321, 192.4599), (580992.507, 4275268.8391, 192.4209), (580992.507, 4275268.8391, 192.4209)
嗯,numba 是否处理列表,它是否需要是一个 numpy 数组,cdist 是否会处理一个 numpy 数组...?
错误
numba.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Untyped global name 'cdist': cannot determine Numba type of <class 'function'>
File "scratch_28.py", line 132:
def near_dist_top(T, B):
<source elided>
XA = [T[i]]
disti = cdist(XA, XB, metric='euclidean').min()
^
解决方案
推荐阅读
- javascript - 嵌入在 JS 中的 Google Calendar API 密钥?
- selenium-webdriver - selenium testng xml类并行运行
- debugging - VS Code 调试可以使用 sourceMapPathOverrides 和 serverReadyAction / debugWithChrome 吗?
- flutter - Flutter 网页上传文件
- npm - 如何使用 $npm_package 变量在 npm package.json 中设置包版本标记?
- react-native - 如何更改条形图中的 x 轴和 y 轴位置(React Native)
- asp.net-core - 会员服务提供者 SignInManager SignInAsync 成功,但 IsSignedIn 始终为 false
- django - 使用 nginx 在多个端口上重定向 Django 站点请求
- amazon-web-services - 如何使用 CloudFormation 创建一个带有 DocumentType 包的“AWS::SSM::Document”
- angular - 如何将外部边框应用于有角材料的表格?