更新时间:2022-11-14 09:10:20
我不知道有什么干净的方法来做这样的事情:
I don't know of a clean way to do something like this:
mask = np.ones(a.shape,dtype=bool) #np.ones_like(a,dtype=bool)
mask[indices] = False
a[~mask] = 999
a[mask] = 888
当然,如果您更喜欢使用 numpy 数据类型,则可以使用 dtype=np.bool_
-- 输出不会有任何区别.这真的只是一个偏好问题.
Of course, if you prefer to use the numpy data-type, you could use dtype=np.bool_
-- There won't be any difference in the output. it's just a matter of preference really.