我目前正在使用Map,其中的值是整数类型,但是每次执行操作时,我都需要更新键的值。示例:如果在执行操作后Map为{“ key1”:1},则其应为{“ key1”:2},依此类推。这是我的代码:
detections = []
while True:
maxloc = np.unravel_index(np.argmax(scmap),
scmap.shape)
if scmap[maxloc] > 0.9:
# other code ..
detections.append(maxloc)
scmap[maxloc] = 0
# after that, what i did is calculating the euclidean distance
# between each pair and excluded the ones that does not meet the
# threshold
_order是地图
答案 0 :(得分:1)
添加return
,否则地图将始终被_order[product.name] = 1;
覆盖
void addToMap(Product product) {
if (_order.containsKey(product.name)) {
_order.update(product.name, (int) => _order[product.name]+1);
return;
}
_order[product.name] = 1;
}