Hello everyone:
So, I have a bit of a python related question, but I wasn't sure where
exactly to ask this. Currently, I've generated a 8000x20 matrix of taylor
series expansion coefficients. So, basically, I had 8000 functions, and I
computed the first 20 taylor series coefficients of each functions and then
put all that into a list of lists(where each row is the 20 taylor series
coefficients). I would like to now compare the first n elements of each row
against every other row and, if the first n elements are the same but the
n+1 element is different, I'd like to get the number of the rows that had
that relationship. If it's too difficult to get the row numbers, I'd like
to just have a counter that goes up by one for every time two rows have
this relationship. For example, if I did n=3, I'd want it to get the first
three elements of each row against each other for equality and, in the
cases that two rows have the same first 3 elements, then I'd want it to
check the fourth element to see if it's different. If the first 3 are the
same but the 4th is different, I want it to tell me that that happened.
I have a basic idea of how to do this using for loops but it seems really
inefficient. It would be something like:
counter = 0
for i in [0..7998]:#I take it to 7998 instead of 7999 so that when it calls
list[j+1], it won't go out of bounds
for j in [i..7999]:
if list[j][:3].equals(list[j+1][:3]) && list[j][4] != list[j+1][4]:
counter = counter + 1
That's about my idea right now. Do you have any tips or tricks to make it
faster? Are there any list comprehension tricks I'm missing? Thanks in
advance!
--
You received this message because you are subscribed to the Google Groups
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.