[Numpy-discussion] restrictions on fancy indexing
Fri Sep 17 13:04:56 CDT 2010
On 17 September 2010 13:47, Neal Becker <firstname.lastname@example.org> wrote:
> It's nice I can do:
> f = np.linspace (0, 1, 100)
> u[f<.1] = 0
> cool, this seems to work also:
> u[np.abs(f)<.1] = 0
> cool! But exactly what kind of expressions are possible here? Certainly
> not arbitrary code.
The short answer is, anything that yields a boolean or integer array.
There's no syntactical magic here. It might be clearer to write it as:
c = np.abs(f)<.1
u[c] = 0
As for what generates boolean arrays, well, they're just numpy arrays,
you can mangle them any way you want. But in particular, < > == != are
operators that take two arrays and yield a boolean array. Also useful
are ~ | and &, which are the logical operators on boolean arrays.
More information about the NumPy-Discussion