如何解决Python TypeError:“只能将整数标量数组转换为标量索引”

时间:2019-04-11 05:43:38

标签: python integer scalar

为什么我会收到以下异常?我该怎么解决?

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')

0 个答案:

没有答案