Hi Harald,
You answered I should of phrased that question better, but lets say I
created a matrix in Sage, and I want to save it as a csv file how do I
do that?
The matrix is made from the following function below
Def function(A,D)
(syntex for making matrix P)
return P
Kind Regards
Chappman
On Feb 24, 6:03 pm, Harald Schilly <[email protected]> wrote:
> On Friday, February 24, 2012 11:13:53 AM UTC+1, Chappman wrote:
>
> > and then using a function which opens up the CSV file and utilizes the
> > entires in the matrix P, from the CSV file.
> > Is there a method for this?
>
> uhm, i'm not sure if you ask about reading or writing. also, your "d" in
> def is uppercase.
>
> reading from this file matrix.csv:
> 1,2,3
> 2,2,-1.1
> 0,0,1
>
> works like this:
> sage: import csv
> sage: data = list(csv.reader(file("matrix.csv")))
> sage: m = matrix([[ float(_) for _ in line] for line in data])
> sage: m
> [ 1.0 2.0 3.0]
> [ 2.0 2.0 -1.1]
> [ 0.0 0.0 1.0]
>
> the other way around works like this (i print this, writing to the file is
> trivial)
>
> for line in m.rows():
> print ','.join((str(_) for _ in line))
>
> gives
>
> 1.0,2.0,3.0
> 2.0,2.0,-1.1
> 0.0,0.0,1.0
>
> h
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org