Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

It would have helped you (and others) if you had given a simpler example above and/or if you had posted the error you were getting. My explanation below is based on my own experimentation and it might not match what you are actually doing in your problem.

I suspect that your problems stem from the fact that result is a matrix (which is not mentioned in the question) and result[:,0] returns a vector due to which zip(ts, result[:,0]) returns a pair of values which looks like (float, (float)). Note that the second element is a tuple and not just a floating point number. To overcome this problem you need to just get a list out of result[:,0] which is obtained by result[:,0].list(). Then the output of zip gives a tuple of floats. Below is an example with integers so that it is easier to see what is going on.

sage: result = random_matrix(ZZ, 2, 2)
sage: ts = random_vector(ZZ, 2)
sage: print "incorrect: ", zip(ts,result[:,0])
incorrect:  [(9, (1)), (1, (-1))]
sage: print "correct: ", zip(ts,result[:,0].list())
correct:  [(9, 1), (1, -1)]

It would have helped you (and others) if you had given a simpler example above and/or if you had posted the error you were getting. My explanation below is based on my own experimentation and it might not match what you are actually doing in your problem.

I suspect that your problems stem from the fact that result is a matrix (which is not mentioned in the question) and result[:,0] returns a vector due to which zip(ts, result[:,0]) returns a pair of values which looks like (float, (float)). Note that the second element is a tuple vector and not just a floating point number. To overcome this problem you need to just get a list out of result[:,0] which is obtained by result[:,0].list(). Then the output of zip gives a tuple of floats. Below is an example with integers so that it is easier to see what is going on.

sage: result = random_matrix(ZZ, 2, 2)
sage: ts = random_vector(ZZ, 2)
sage: print "incorrect: ", zip(ts,result[:,0])
incorrect:  [(9, (1)), (1, (-1))]
sage: print "correct: ", zip(ts,result[:,0].list())
correct:  [(9, 1), (1, -1)]