在这种情况下,您要使用掩码数组,它可以保持数组的形状,并且可以被所有numpy和matplotlib函数自动识别。
X = np.random.randn(1e3, 5)X[np.abs(X)< .1]= 0 # some zerosX = np.ma.masked_equal(X,0)plt.boxplot(X) #masked values are not plotted#other functionalities of masked arraysX.compressed() # get normal array with masked values removedX.mask # get a boolean array of the maskX.mean() # it automatically discards masked values



