[Numpy-discussion] restrictions on fancy indexing

2010-09-17 Thread Neal Becker
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.


___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] restrictions on fancy indexing

2010-09-17 Thread John Salvatier
There's a tutorial here: http://www.scipy.org/Cookbook/Indexing

Look down for the section on Fancy Indexing.

On Fri, Sep 17, 2010 at 10:47 AM, Neal Becker ndbeck...@gmail.com 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.


 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] restrictions on fancy indexing

2010-09-17 Thread Anne Archibald
On 17 September 2010 13:47, Neal Becker ndbeck...@gmail.com 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.

Anne
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] restrictions on fancy indexing

2010-09-17 Thread Eric Firing
On 09/17/2010 08:04 AM, Anne Archibald wrote:
 On 17 September 2010 13:47, Neal Beckerndbeck...@gmail.com  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.

It can be important to bear in mind that they are not actually logical 
operators, they are bitwise operators pressed into service. 
Functionally, they substitute for logical operators on boolean arrays, 
but one must watch out for their high precedence.  This typically 
requires using parentheses where they would not be needed for the true 
python logical operators:

With python scalars:  a  b and c  d
With numpy arrays:(a  b)  (c  d)

Eric


 Anne
 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion