473,401 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Numeric array equivalent of index ?

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
1 2013
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: jerrygarciuh | last post by:
Hello, In reading through the list of array-related functions I did not find on which returns the numeric index where the array's internal pointer currently sits. Is there such a function? ...
6
by: Gaubitzer Erwin | last post by:
Hi there I wrote a short program which reads scientific data from a file and stores its values in a Numeric array. At the same time it reads the names of its dimensions which are then in the...
6
by: Michael Drumheller | last post by:
(If you're not interested in NumArray, please skip this message.) I am new to NumArray and I wonder if someone can help me with array-indexing. Here's the basic situation: Given a rank-2 array...
5
by: George Sakkis | last post by:
What's the fastest and most elegant equivalent of zip() in Numeric/Numarray between two equally sized 1D arrays ? That is, how to combine two (N,)-shaped arrays to one (N,2) (or (2,N)) shaped ? I...
14
by: Steven Taylor | last post by:
I'm learning C++ from C++ Primer Plus 5th edition. I'm struggling at the moment with declaring an array of three structures by using 'new' to allocate memory. (this is one of the programming...
30
by: Dr John Stockton | last post by:
It has appeared that ancient sources give a method for Numeric Date Validation that involves numerous tests to determine month length; versions are often posted by incomers here. That sort of code...
47
by: VK | last post by:
Or why I just did myArray = "Computers" but myArray.length is showing 0. What a hey? There is a new trend to treat arrays and hashes as they were some variations of the same thing. But they...
3
by: daniel.neilson | last post by:
I have two one-dimensional Numeric arrays, and I need to know the indices in the second array of elements from the first. so if i had: a=array() b=array() i want a function match that does...
7
by: Sheldon | last post by:
Hi, I have the following loop that I think can be written to run faster in Numeric. I am currently using Numeric. range_va = main.xsize= 600 main.ysize= 600 #msgva is an (600x600) Numeric...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.