Which rule wins when several risk bands match?

select chooses the first matching condition in list order and uses a default where no condition holds.

numpy.select in practice

A score of 95 exceeds both 90 and 70. Put the stricter rule first to reach the high band. Reversing the two rules can hide that band entirely.

import numpy as np
v=np.array([60,75,95])
np.select([v>90,v>70],[2,1],default=0)

Result [0, 1, 2]

中文

多条风险分级规则同时命中时取哪一条?

select 按条件列表的先后顺序选择首个为真的选项,没有命中时使用默认值。

numpy.select 算例

数值 95 同时超过 90 和 70,把更严格阈值放前才能标为高档。调换规则顺序可能吞掉最高档。

import numpy as np
v=np.array([60,75,95])
np.select([v>90,v>70],[2,1],default=0)

结果 [0, 1, 2]

References / 参考来源

Keep reading / 继续阅读