0

我正在尝试创建一个包含 image_id 然后几个预测百分比的列表。预测百分比 (yhat) 在 np 数组中。我认为使用“tolist”然后“扩展”然后“附加”应该可以工作。我一定做错了什么。非常感谢您的帮助!

# Predict the probability across all output classes.
yhat = model.predict(image_array) #the image predictions
yhat.tolist() #change array to list
row = [i[0]] #the image id 
row.extend(yhat) #add list elements to row
result_yhat.append(row) #append row to result_yhat

结果仍然具有数组中的预测数字。

result_yhat
[['5', array([6.78813876e-07, 1.14646399e-08, 5.51704140e-08, 
    9.05712838e-08,...
4

1 回答 1

0

我认为您想将结果分配给yhat.tolist()变量并将其传递给append().

否则,您只是将 np 数组传递给append().

yhat = yhat.tolist() #change array to list
row = [i[0]] #the image id 
row.extend(yhat) #add list elements to row
于 2019-04-17T18:08:25.960 回答