可以用成员函数where()实现这一需求。
详情见博文 https://blog.csdn.net/wenhao_ir/article/details/125295819
需要补充说明一点的是:成员函数where()不支持选择介于某个范围的值,即下面的写法是错误的:
A2 = np.where(3 < A1 < 5, 100, A1)
这样写,会报下面的错误:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()