How do you switch between predictions item by item?

where draws from the first candidate wherever a condition holds and from the second elsewhere, using broadcasting if needed.

numpy.where in practice

Only the middle order needs a manual quote. A mask selects that quote. Both candidate expressions are evaluated before the call, which matters if one contains invalid arithmetic.

import numpy as np
np.where([False,True,False], [99,88,77], [10,20,30])

Result [10, 88, 30]

中文

如何按逐项条件切换两组预测?

where 在条件为真处选第一个候选值,在其余位置选第二个,候选数组可广播。

numpy.where 算例

三笔订单中只有中间一笔需人工报价,用掩码替换这笔即可。传入的两个候选表达式会先被求值,不能借它跳过无效运算。

import numpy as np
np.where([False,True,False], [99,88,77], [10,20,30])

结果 [10, 88, 30]

References / 参考来源

Keep reading / 继续阅读