473,473 Members | 1,477 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Re: Fastest way to max() list

On Fri, Sep 26, 2008 at 7:22 AM, David Di Biase <da**********@gmail.comwrote:
Hi Chris,

Yeah I hear you on point A. but this the specification I was given, so I
have to follow it unfortunately. I've also been restricted and not allowed
to use any other packages. I was using NumPy earlier (should have mentioned
that) but I was wondering if there was a simpler way. Is NumPy technically
even faster than just iterating and modifying the list directly?

Also if I'm creating an array then making it,
Uh, this part of your sentence doesn't quite make sense...
why not just do a temporary
sort and capture the first and last values? Is this method you've provided
supposed to be faster?
Well, unless you're going to use the rest of the sorted values at some
point in your program and since you have a large quantity of data,
yes, my way ought to be faster. Sorting the list is O(N*log(N)) while
running max and min over the list is only O(N).

Regards,
Chris
>
Dave

On Fri, Sep 26, 2008 at 12:42 AM, Chris Rebert <cl*@rebertia.comwrote:
>>
On Thu, Sep 25, 2008 at 8:57 PM, David Di Biase <da**********@gmail.com>
wrote:
I have a list with about 1000-1500 sub-lists which look like so:
list[-0.28817955213290786, 3.6693631467403929, 'H', 31.31225233035784]]

The first and second values are Angstrom units specifying the location
of a
particle. What I'd like to do is determine the distance between the
smallest
and largest value in the arrays first position 0. I tried reading the
manual
for this but I don't see how it applies key or any of those other
commands
to the function. I could easily write a sort to do this and capture the
first and last spots, but why do that when I can use max and min (if I
can
actually do that...).

A. You should probably be using objects rather than arrays to
represent your datapoints, so that they're more structured and it's
more apparent what the values mean.

B. Assuming by "distance" you meant "difference" and/or that the
distance is only in 1 dimension:

from operator import itemgetter
firsts = map(itemgetter(0), main_list)
distance = max(firsts) - min(firsts)
>
So you wonderful Python gods, lay some knowledge on me. please? lol...

while I'm at it, is there a way to modify an entire list without having
to
produce a whole new one? For example now say I want to modify list[0]
and
multiply it by some value. From what I understand previous version of
Python
allowed lists to be multiplied like matrices...now apparently it just
replicates the list. :-/ shucks...

You just have to apply the transform to each list element individually
(also, you might consider using NumPy [http://numpy.scipy.org/] if
you're doing a lot of matrix manipulation):

for lst in main_list:
lst[0] *= some_value

Regards,
Chris
>
The first question would be useful to know, but the second question I do
quite a bit of and the "best practice" would be really great to know!

Thanks in advanced!

--
http://mail.python.org/mailman/listinfo/python-list
--
Follow the path of the Iguana...
http://rebertia.com



--
Follow the path of the Iguana...
http://rebertia.com
Sep 26 '08 #1
0 1310

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Simon | last post by:
Hi, If I have a string, (variable len), and I am looking for the first position of one char in array starting from position 'x' For example, // the 'haystack' $string = "PHP is great,...
9
by: Rune Strand | last post by:
Hi, If I have a lot of integers and want do something with each digit as integer, what is the fastest way to get there? Eg. Make 12345 into an iterable object, like or "12345" (Btw: What is...
6
by: Jonathan | last post by:
I am hoping that someone more experienced than myself can point me towards what might be the fastest data lookup method to use for storing ip addresses. My situation is that I will need to maintain...
4
by: John A Fotheringham | last post by:
I've probably not given the best title to this topic, but that reflects my relative "newbie" status. I have a table that goes essentially TS DATETIME jobnumber VARCHAR jobentry VARCHAR ...
11
by: hoopsho | last post by:
Hi Everyone, I am trying to write a program that does a few things very fast and with efficient use of memory... a) I need to parse a space-delimited file that is really large, upwards fo a...
10
by: Erik Max Francis | last post by:
For a file hashing system (finding similar files, rather than identical ones), I need to be able to efficiently and quickly sum the ordinals of the bytes of a file and their squares. Because of...
2
by: king imran | last post by:
I am giving u complete code. It works properly But add max and mean functions so that it can work properly. * /LinkList.h/ * #include "Node.h" * /* The LinkList class declaration*/ class**...
19
by: Eugeny Myunster | last post by:
I know, only simple one: #include <stdio.h> int main() { int min=0,max=0,i,arr; for(i=0;i<12;i++) arr=rand()%31-10; for(i=0;i<12;i++)
0
by: Chris Rebert | last post by:
On Thu, Sep 25, 2008 at 8:57 PM, David Di Biase <dave.dibiase@gmail.comwrote: A. You should probably be using objects rather than arrays to represent your datapoints, so that they're more...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.