手动广播布尔表达式中的numpy吗?

时间:2019-03-21 11:21:44

标签: numpy broadcast

为什么numpy无法广播以下表达式?

moves[rf_current> rf_max] = np.nan

形状如下:

moves.shape = (5,4)
rf_max.shape = (5,1)
rf_current.shape = (5,1)

我必须手动广播rf_current才能正常工作,还是有更好的方法?

当前出现错误:

IndexError: boolean index did not match indexed array along dimension 1; dimension is 4 but corresponding boolean dimension is 1

可以通过用rf_current = np.broadcast_to(rf_current, moves.shape)替换rf_current来轻松解决。但是我觉得应该避免这种情况。任何建议表示赞赏。

0 个答案:

没有答案