[Numpy-discussion] Addressing arrays
Mon Jan 30 12:29:38 CST 2012
> 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.
I think that your best bet is to form the boolean masks independently and then logical-and them together:
mask = (a['month'] == 1) & (a['year'] == 1960)
jan_60 = a[mask]
Someone might have more insight here. Though I should note that if you have large data and are doing lots of "queries" like this, a more database-ish approach might be better. Something like sqlite's python bindings, or PyTables.
Alternately, if your data are all time-series based things, PANDAS might be worth looking at.
But the above approach should be just fine for non-huge datasets...
More information about the NumPy-Discussion