[Numpy-discussion] Addressing arrays

Ted To rainexpected@theo...
Mon Jan 30 12:39:13 CST 2012


> You'd want to update your mask appropriately to get everything you
> want to select, one criteria at a time e.g.:
> mask = a[:,0] == 1
> mask &= a[:,1] == 1960
> 
> Alternatively:
> mask = (a[:,0] == 1) & (a[:,1] == 1960)
> but be careful with the parens, & and | are normally high-priority
> bitwise operators and if you leave the parens out, it will try to
> bitwise-and 1 and a[:,1] and throw an error.
> 
> If you've got a ton of parameters, you can combine these more
> aesthetically with:
> mask = (a[:,[0,1]] == [1, 1960]).all(axis=1)
> 
> ~Brett

Zach and Brett,

Many thanks -- that is exactly what I need.

Cheers,
Ted


More information about the NumPy-Discussion mailing list