numpy how to dropzero

Solutions on MaxInterview for numpy how to dropzero by the best coders in the world

showing results for - "numpy how to dropzero"
Diego Alejandro
04 Jan 2020
1X = np.random.randn(1e3, 5)
2X[np.abs(X)< .1]= 0 # some zeros
3X = np.ma.masked_equal(X,0)
4plt.boxplot(X) #masked values are not plotted
5
6#other functionalities of masked arrays
7X.compressed() # get normal array with masked values removed
8X.mask # get a boolean array of the mask
9X.mean() # it automatically discards masked values