On 01/30/2012 12:13 PM, Brett Olsen wrote: > On Mon, Jan 30, 2012 at 10:57 AM, Ted To <rainexpec...@theo.to> wrote: >> Sure thing. To keep it simple suppose I have just a two dimensional >> array (time,output): >> [(1,2),(2,3),(3,4)] >> I would like to look at all values of output for which, for example time==2. >> >> My actual application has a six dimensional array and I'd like to look >> at the contents using one or more of the first three dimensions. >> >> Many thanks, >> Ted > > Couldn't you just do something like this with boolean indexing: > > In [1]: import numpy as np > > In [2]: a = np.array([(1,2),(2,3),(3,4)]) > > In [3]: a > Out[3]: > array([[1, 2], > [2, 3], > [3, 4]]) > > In [4]: mask = a[:,0] == 2 > > In [5]: mask > Out[5]: array([False, True, False], dtype=bool) > > In [6]: a[mask,1] > Out[6]: array([3]) > > ~Brett
Thanks! That works great if I only want to search over one index but I can't quite figure out what to do with more than a single index. So suppose I have a labeled, multidimensional array with labels 'month', 'year' and 'quantity'. a[['month','year']] gives me an array of indices but "a[['month','year']]==(1,1960)" produces "False". I'm sure I simply don't know the proper syntax and I apologize for that -- I'm kind of new to numpy. Ted _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion