# Finding vectors from csv file

Hi! I'm trying to find 2 vectors x and y coming from the colums of my csv file.
Let's say that it looks like :

0.30075188 3.565635718
0.325814536 3.04256687
0.350877193 3.850427654
0.37593985 3.954295131
0.401002506 4.265641679

Thanks a lot!

edit retag close merge delete

1

Can you please explain what you are trying to do? The question is not clear to me. Are you trying to find the line which has a vector with given x and y coordinates(first and second column)?

( 2013-10-31 16:15:27 +0200 )edit

Yes that's what I want to do!

( 2013-10-31 17:38:11 +0200 )edit

Sort by ยป oldest newest most voted

I am not sure i understood your question.

If you want to transform each column into a vector, you can try something like:

sage: reader=csv.reader(open('/tmp/file.csv'), delimiter=' ')
sage: M = matrix([[RR(a),RR(b)] for a,b in reader])
sage: M
[0.300751880000000  3.56563571800000]
[0.325814536000000  3.04256687000000]
[0.350877193000000  3.85042765400000]
[0.375939850000000  3.95429513100000]
[0.401002506000000  4.26564167900000]
sage: v0, v1 = M.column(0), M.column(1)
sage: v0
(0.300751880000000, 0.325814536000000, 0.350877193000000, 0.375939850000000, 0.401002506000000)
sage: v1
(3.56563571800000, 3.04256687000000, 3.85042765400000, 3.95429513100000, 4.26564167900000)
sage: v0.parent()
Vector space of dimension 5 over Real Field with 53 bits of precision


If you want to find the line which has a vector with given x and y coordinates(first and second column), you can do something like:

sage: reader=csv.reader(open('/tmp/file.csv'), delimiter=' ')
sage: L = [(RR(a),RR(b)) for a,b in reader]
sage: L
[(0.300751880000000, 3.56563571800000),
(0.325814536000000, 3.04256687000000),
(0.350877193000000, 3.85042765400000),
(0.375939850000000, 3.95429513100000),
(0.401002506000000, 4.26564167900000)]
sage: (x,y) in L
True
sage: L.index((x,y))
2
sage: L = [(RR(a),RR(b)) for a,b in reader]
sage: L
[(0.300751880000000, 3.56563571800000),
(0.325814536000000, 3.04256687000000),
(0.350877193000000, 3.85042765400000),
(0.375939850000000, 3.95429513100000),
(0.401002506000000, 4.26564167900000)]
sage: (x,y) = (0.350877193000000, 3.85042765400000)
sage: (x,y) in L
True
sage: L.index((x,y))
2
sage: (x,y) = (11, 12)
sage: (x,y) in L
False

more