<div dir="ltr">Yeah,<br><br>Apologies, it's been a long day for me. It works, just have to check if the nazis I'm doing this for will allow me to use object and NumPy. ack.<br><br>Thanks again,<br><br>Dave<br><br><div class="gmail_quote">
On Fri, Sep 26, 2008 at 2:08 PM, Chris Rebert <span dir="ltr"><<a href="mailto:clp@rebertia.com">clp@rebertia.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">On Fri, Sep 26, 2008 at 7:22 AM, David Di Biase <<a href="mailto:dave.dibiase@gmail.com">dave.dibiase@gmail.com</a>> wrote:<br>
> Hi Chris,<br>
><br>
> Yeah I hear you on point A. but this the specification I was given, so I<br>
> have to follow it unfortunately. I've also been restricted and not allowed<br>
> to use any other packages. I was using NumPy earlier (should have mentioned<br>
> that) but I was wondering if there was a simpler way. Is NumPy technically<br>
> even faster than just iterating and modifying the list directly?<br>
><br>
> Also if I'm creating an array then making it,<br>
<br>
</div>Uh, this part of your sentence doesn't quite make sense...<br>
<div class="Ih2E3d"><br>
> why not just do a temporary<br>
> sort and capture the first and last values? Is this method you've provided<br>
> supposed to be faster?<br>
<br>
</div>Well, unless you're going to use the rest of the sorted values at some<br>
point in your program and since you have a large quantity of data,<br>
yes, my way ought to be faster. Sorting the list is O(N*log(N)) while<br>
running max and min over the list is only O(N).<br>
<br>
Regards,<br>
<font color="#888888">Chris<br>
</font><div><div></div><div class="Wj3C7c"><br>
><br>
> Dave<br>
><br>
> On Fri, Sep 26, 2008 at 12:42 AM, Chris Rebert <<a href="mailto:clp@rebertia.com">clp@rebertia.com</a>> wrote:<br>
>><br>
>> On Thu, Sep 25, 2008 at 8:57 PM, David Di Biase <<a href="mailto:dave.dibiase@gmail.com">dave.dibiase@gmail.com</a>><br>
>> wrote:<br>
>> > I have a list with about 1000-1500 sub-lists which look like so:<br>
>> > list[-0.28817955213290786, 3.6693631467403929, 'H', 31.31225233035784]]<br>
>> ><br>
>> > The first and second values are Angstrom units specifying the location<br>
>> > of a<br>
>> > particle. What I'd like to do is determine the distance between the<br>
>> > smallest<br>
>> > and largest value in the arrays first position 0. I tried reading the<br>
>> > manual<br>
>> > for this but I don't see how it applies key or any of those other<br>
>> > commands<br>
>> > to the function. I could easily write a sort to do this and capture the<br>
>> > first and last spots, but why do that when I can use max and min (if I<br>
>> > can<br>
>> > actually do that...).<br>
>><br>
>> A. You should probably be using objects rather than arrays to<br>
>> represent your datapoints, so that they're more structured and it's<br>
>> more apparent what the values mean.<br>
>><br>
>> B. Assuming by "distance" you meant "difference" and/or that the<br>
>> distance is only in 1 dimension:<br>
>><br>
>> from operator import itemgetter<br>
>> firsts = map(itemgetter(0), main_list)<br>
>> distance = max(firsts) - min(firsts)<br>
>><br>
>> ><br>
>> > So you wonderful Python gods, lay some knowledge on me. please? lol...<br>
>> ><br>
>> > while I'm at it, is there a way to modify an entire list without having<br>
>> > to<br>
>> > produce a whole new one? For example now say I want to modify list[0]<br>
>> > and<br>
>> > multiply it by some value. From what I understand previous version of<br>
>> > Python<br>
>> > allowed lists to be multiplied like matrices...now apparently it just<br>
>> > replicates the list. :-/ shucks...<br>
>><br>
>> You just have to apply the transform to each list element individually<br>
>> (also, you might consider using NumPy [<a href="http://numpy.scipy.org/" target="_blank">http://numpy.scipy.org/</a>] if<br>
>> you're doing a lot of matrix manipulation):<br>
>><br>
>> for lst in main_list:<br>
>>    lst[0] *= some_value<br>
>><br>
>> Regards,<br>
>> Chris<br>
>><br>
>> ><br>
>> > The first question would be useful to know, but the second question I do<br>
>> > quite a bit of and the "best practice" would be really great to know!<br>
>> ><br>
>> > Thanks in advanced!<br>
>> ><br>
>> > --<br>
>> > <a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
>> ><br>
>> --<br>
>> Follow the path of the Iguana...<br>
>> <a href="http://rebertia.com" target="_blank">http://rebertia.com</a><br>
><br>
><br>
<br>
<br>
<br>
</div></div>--<br>
<div><div></div><div class="Wj3C7c">Follow the path of the Iguana...<br>
<a href="http://rebertia.com" target="_blank">http://rebertia.com</a><br>
</div></div></blockquote></div><br></div>