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?
it's not clear what these A and D are supposed to be,
and how this would be different
from creating a Sage matrix like this, for instance:
M=matrix([[1,2],[3,4]])
and then writing entries of M, i.e. M[0,0], M[0,1], etc,
into CSV file using csv.writer().
Dmitrii
> --
> To post to this group, send email to sage-s...@googlegroups.com
> To unsubscribe from this group, send email to sage-support...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/sage-support
> URL: http://www.sagemath.org
>
How about the matrix constructor reads from an iterator and recognizes
csv? We could even use the numpy savetxt and loadtxt functions to more
sophisticated parsing.
So:
with open('mymatrix.csv','r') as f:
m=matrix(f)
or
m.save('test.csv') # or m.save('test.csv', format='csv')
I'm not volunteering in these suggestions...
Thanks,
Jason
matrix(open("test.csv").read())
just like
matrix("""
1,2,3
4,5,5
""")
That's not the difference.
> I agree that this problem arises if we would allow the c's themselves
> to just be generic iterators, which would include strings.
Yep. I don't like matrix(["1 2", "3 4"]) because that's impossible to
distinguish (using types alone) from matrix(["1", "2", "3", "4"]) (or
the same replacing lists with iterators). Iterating over open("file"))
iterates over the lines which would typically be entire rows.
Interpreting strings as a 1-digit decimal list seems more broken to me
sage: MatrixSpace(SR, 2, 2)("1234")
[1234 0]
[ 0 1234]
sage: MatrixSpace(ZZ, 2, 2)("1234")
[1 2]
[3 4]
I think it's fair to test for strings first, trying to parse, before
testing if it's an iterator. This is consistant with many other
objects that try to "parse" their string representations.
sage: ZZ['x']([1,2,3])
3*x^2 + 2*x + 1
sage: ZZ['x']("123")
123
sage: ZZ['x']("x^2 + 5")
x^2 + 5
- Robert
Yep, that's the basic idea, though I might test for the non-iterable
matrix initializers first, so something like matrix(QQ['x'], 2, x^2)
becomes
[x^2, 0]
[0, x^2]
rather than using list(x^2), and an iterable of strings is always
considered an iterator of elements, not an iterator of rows.
- Robert