python - removing data from a numpy.array -


i have rank-1 numpy.array of want make boxplot. however, want exclude values equal 0 in array ... currently, solved looping array , copy value new array if not equal zero. however, array consists of 86 000 000 values , have multiple times, takes lot of patience.

is there more intelligent way ?

thx in advance

this case want use masked arrays, keeps shape of array , automatically recognized numpy , matplotlib functions.

x = np.random.randn(1e3, 5) x[np.abs(x)< .1]= 0 # zeros x = np.ma.masked_equal(x,0) plt.boxplot(x) #masked values not plotted  #other functionalities of masked arrays x.compressed() # normal array masked values removed x.mask # boolean array of mask x.mean() # automatically discards masked values 

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -