np.where()有两种使用方法 np.where(condition,x,y) np.where(condition) 1、np.where(condition,x,y) 若满足条件condition,输出x,否则输出y import numpy as np import numpy as np aa = np.arange(5) print(aa) [0 1 2 3 4] 为false np.where(aa,1,-1) #aa[0]==0,故为false array([-1, 1, 1