[SciPy-User] scikits.timeseries, element-wise allocation with double boolean expressions

Matt Knox mattknox.ca at gmail.com
Tue Sep 29 21:44:53 EDT 2009


Martin Enlund <martin.enlund <at> gmail.com> writes:

> 
> Hi there. I am sure this is simple to do, but since I am failing all
> the time I turn to you!
> 
> I am trying something like this: (dest,a,b,c,d are all the simplest
> possible timeseries)
> dest[:]=0
> dest[a > b and c > d] = 1

I think you are just looking for the & operator.

So instead of
>>> dest[a > b and c > d] = 1

you would have
>>> dest[(a > b) & (c > d)] = 1

I forget what the operator precedence is here, best to use brackets to be
explicit.

For "or" it is |

Note that this is not anything unique to the timeseries scikit but applies to
indexing with boolean arrays in numpy in general.

- Matt




More information about the SciPy-User mailing list