Ask Your Question
0

Finding vectors from csv file

asked 2013-10-31 10:02:54 -0500

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 flag offensive close merge delete

Comments

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)?

Shashank gravatar imageShashank ( 2013-10-31 10:15:27 -0500 )edit

Yes that's what I want to do!

ndanvery gravatar imagendanvery ( 2013-10-31 11:38:11 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-10-31 11:06:10 -0500

tmonteil gravatar image

updated 2013-10-31 12:42:31 -0500

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: 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) = (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
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-10-31 10:02:54 -0500

Seen: 83 times

Last updated: Oct 31 '13