小编Mik*_*ke 的帖子

如何在numpy数组中编写case when like语句

def custom_asymmetric_train(y_true, y_pred):
    residual = (y_true - y_pred).astype("float")
    grad = np.where(residual>0, -2*10.0*residual, -2*residual)
    hess = np.where(residual>0, 2*10.0, 2.0)
    return grad, hess
Run Code Online (Sandbox Code Playgroud)

我想写下这样的声明:

    case when residual>=0 and residual<=0.5 then -2*1.2*residual
    when residual>=0.5 and residual<=0.7 then -2*1.*residual
    when residual>0.7 then -2*2*residual end ) 
Run Code Online (Sandbox Code Playgroud)

但是np.where不能写 &(and) 逻辑。当逻辑在 python 中时,我该如何编写这种情况np.where

谢谢

python numpy numpy-ndarray

6
推荐指数
2
解决办法
999
查看次数

标签 统计

numpy ×1

numpy-ndarray ×1

python ×1