where function
Steven Bethard
steven.bethard at gmail.com
Sun Mar 18 19:17:33 EDT 2007
vorticitywolfe at gmail.com wrote:
> Is there a function in Python analogous to the "where" function in
> IDL?
>
> x=[0,1,2,3,4,2,8,9]
> print where(x=2)
>
> output:
> [2,5]
If you're doing a lot of this kind of thing, you probably want to use
numpy::
>>> import numpy
>>> x = numpy.array([0, 1, 2, 3, 4, 2, 8, 9])
>>> numpy.where(x == 2)
(array([2, 5]),)
You can find numpy here:
http://numpy.scipy.org/
STeVe
More information about the Python-list
mailing list