[Numpy-discussion] array operation

Chris Barker Chris.Barker at noaa.gov
Tue Jan 21 14:30:10 CST 2003


Perry Greenfield wrote:

> If so then for numarray this ought to work.
> 
> index = nonzero(code==1) # want indices of all the obs where class code = 1
> selected_obs = data[index]

of for Numeric, use take():

selected_obs = take(data,nonzero(code == 1),1)

(this will select columns coresponding to where the code == 1, which is
how I read your question)


By the way, choose() and where() do something similar, but give you an
array back that is the saem size as the one you start with, with some
(or all) of the elements replaced. take() gives you a smaller array that
is a subset of the original one, which I think is what you want here.

-Chris



-- 
Christopher Barker, Ph.D.
Oceanographer
                                    		
NOAA/OR&R/HAZMAT         (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov




More information about the Numpy-discussion mailing list