Numeric and matlab
Brian Blais
bblais at bryant.edu
Mon Feb 6 08:27:43 EST 2006
Bas wrote:
> I am also considering a switch from Matlab to NumPy/SciPy at some
> point.
>
> Note that in the last version of Matlab (7?) you don't have to use
> 'find', but you now can 'conditional arrays' as an index, so instead
> of
> idx=find(a>5);
> a(idx)=6;
> you can do:
> cond=a>5;
> a(cond) = 6;
> or even shorter
> a(a>5) = 6;
>
> Does someone know if the same trick is possible in NumPy?
>
A response I got back from someone else is, yes. I tested it, and it works in numpy.
You can do:
import numpy
a=numpy.arange(0,10,.1)
a[a>5]=6
bb
--
-----------------
bblais at bryant.edu
http://web.bryant.edu/~bblais
More information about the Python-list
mailing list