By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,660 Members | 1,102 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,660 IT Pros & Developers. It's quick & easy.

Numeric array equivalent of index ?

P: n/a
Hello,

I'm trying to find a clear and fast equivalent to the index method of
plain python list :
a = [5,1,4,3,4]
a.index(4) 2

I have to use it on a Numeric array, so the best I've come up with is
(rather ugly I think) : from Numeric import array, equal, nonzero
a = array([5,1,4,3,4])
nonzero(equal(a,4))[0]

2
Does someone know of a more Pythonic way ?

Thanks,
Oct 15 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Nicolas Pernetty wrote:
Hello,

I'm trying to find a clear and fast equivalent to the index method of
plain python list :
a = [5,1,4,3,4]
a.index(4)
2

I have to use it on a Numeric array, so the best I've come up with is
(rather ugly I think) :
from Numeric import array, equal, nonzero
a = array([5,1,4,3,4])
nonzero(equal(a,4))[0]


2

Does someone know of a more Pythonic way ?


There's a list for Numeric. You'll get better answers there.

http://numeric.scipy.org/

And no, no one has bothered adding a .index() equivalent for general,
unsorted arrays.

--
Robert Kern
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter

Oct 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.