> In a numpy array of m x n size, I would like to delete few rows when > a given element in that row is ‘nan’ or say any other value. > > > For e.g. as in example given below, if I wish to delete a row when > the 3rd element of row is zero, or if 3rd, 4th, 5th element are zero > or either of 3rd, 4th and 5th element is zero. > > array([[ 1900. , nan, nan, nan, nan, nan], > > [ 1900.5, nan, nan, nan, nan, nan], > > [ 1901. , nan, nan, nan, nan, nan], > > ..., > > [ 6724. , nan, nan, nan, nan, nan], > > [ 6724.5, nan, nan, nan, nan, nan], > > [ 6725. , nan, nan, nan, nan, nan]]) > > Cheers > > > Sachin > > >
> I think u can use numpy.loadtext command > http://docs.scipy.org/doc/numpy/reference/generated/numpy.loadtxt.html > > > -- > DILEEPKUMAR. R > J R F, IIT DELHI Wouldn't that require to transform the array to a text representation first? If you have an existing array, you can use the numpy test and logical functions to index it. E.g. myarr[:,2] == 0 selects the rows with 3rd column zero, np.isnan(myarr[:,3]) those with 4th column NaN and to select only rows where neither is the case: clean = myarr[np.logical_not( (myarr[:,2]==0) | (np.isnan(darr[:,3])) )] - combine as required with the '&' or '|' operators (there does not seem to be a shorthand for logical_not...), and check np.isnan, np.isinf, np.isfinite - those should allow you to select what you need. HTH, Derek _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion