[Numpy-discussion] Slicing a numpy array and getting the "complement"

Anne Archibald peridot.faceted@gmail....
Mon May 19 14:33:15 CDT 2008

2008/5/19 Orest Kozyar <orest.kozyar@gmail.com>:
>> If you don't mind fancy indexing, you can convert your index arrays
>> into boolean form:
>> complement = A==A
>> complement[idx] = False
> This actually would work perfectly for my purposes.  I don't really
> need super-fancy indexing.

Heh. Actually "fancy indexing" is numpy-speak for indexing with
anything that's not an integer or a slice. In this case, indexing with
a boolean array is "fancy indexing". The reason we make this
distinction is that with slices, the new array you get is actually
just a reference to the original array (so you can modify the original
array through it). With fancy indexing, the new array you get is
actually a copy. (Assigning to fancy-indexed arrays is handled
specially in __setitem__, so it works.)


More information about the Numpy-discussion mailing list