On Tue, Aug 25, 2009 at 11:07, Giuseppe Aprea<giuseppe.ap...@gmail.com> wrote: > Hi list, > > > I wonder if there is any smarter way to apply a filter to a 2 dimensional > array > than a for loop: > > a=array(.......) > idxList=[] > for i in range(0,a.shape[1]): > if (some condition on a[:,i]): > idxList.append(i)
Define a "some condition on a[:,i]" that is of interest to you, and I will show you how to do it. Roughly, you should define a function that takes 'a' and operates on it in bulk in order to get a boolean array of shape (a.shape[0],) evaluating the condition for each column. Then use numpy.where() on that boolean array to get indices if you actually need indices; frequently, you can just use the boolean array where you wanted the indices. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion