import numpy as np a=[1,2,3,4] a=np.array(a) # 大于零为1小于零为0 c = np.where(a>3,1,0) #满足大于0的值保留,不满足的设为0 print(c) [0 0 0 1]