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, 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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?
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
|
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...
|
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...
| |