python - 如何解决 Python TypeError:“只能将整数标量数组转换为标量索引”
问题描述
为什么我会收到以下异常?我该如何解决这个问题?
scores = [(dists[id], img_paths[id]) for id in ids]
TypeError:只有整数标量数组可以转换为标量索引
img = Image.open(file.stream) # PIL image
uploaded_img_path = "static/uploaded/" + datetime.now().isoformat() + "_" + file.filename
img.save(uploaded_img_path)
img = img.resize((224, 224)) # VGG must take a 224x224 img as an input
query = fe.extract(img)
dists = np.linalg.norm(features - query.reshape((64,64,-1)), axis=1) # Do search
ids = np.argsort(dists)[:30] # Top 30 results
scores = [(dists[id], img_paths[id]) for id in ids]
return render_template('index.html',
query_path=uploaded_img_path,
scores=scores)
else:
return render_template('index.html')
解决方案
推荐阅读
- excel - Excel:如果另一列有重复,则只计算一次
- regex - 使用 re.sub 清理嵌套列表
- charts - 如何以编程方式将 Google 表格中的图表作为图像获取
- assembly - 在 V8 中为 x64 生成 cmp 和 cmov 指令
- javascript - reactJS 应用程序 string.replace 未定义
- powershell - 删除本地帐户仅删除 Powershell 中的一半
- batch-file - 使用 SQL Server 代理作业的 WinSCP 批量传输
- reactjs - 在状态中存储动态生成的输入值
- html - 视频在 iframe 悬停时波动
- css - 按钮高度固定,多行文本不显示在相同的垂直位置