[Numpy-discussion] removing and replacing certain values in arrays

Pierre GM pgmdevlist@gmail....
Mon Jul 7 15:25:19 CDT 2008


On Monday 07 July 2008 16:08:36 Tim Michelsen wrote:
> Hello,
> how do I remove all rows (or column) from an array which contain a
> certain  value or sting?

Timmie,
You could try a combination of masking the values you want to discard, 
followed by ma.compress_rows/cols, provided your array is 2D.
For example:
>>> import numpy.ma as ma
>>> x=ma.array([[1,2,3,4,5]])
>>> x[x==3] = ma.masked
>>> ma.compress_cols(x)
array([[1, 2, 4, 5]])



More information about the Numpy-discussion mailing list