[SciPy-User] equivalent of tolist().index(entry) for numpy 1d array of strings

Ryan Krauss ryanlists@gmail....
Mon Dec 21 19:53:19 CST 2009

I wrote some code to work with csv spreadsheet files by reading the
columns into lists, but I need to rework the code to work with numpy
1d arrays of strings rather than lists.  I need to search one of these
columns/arrays.  What is the best way to find the index for the
element that matches a certain string (or maybe just the first element
to match such a string)?

With the columns as lists, I was doing
index = mylist.index(entry)

So, I could obviously do
index = mylist.tolist().index(entry)

but I don't know if that would be slower or clumsier than something like
bool_vect = where(mylist==entry)[0]
index = bool_vect[0]

or just

index = where(mylist==entry)[0][0]

Any thoughts?  Is there an easier way?



More information about the SciPy-User mailing list