On Mar 2, 12:28 am, Robert Bradshaw <[email protected]>
wrote:
> The difficulty with accepting an iterator (of strings) is that it is
> unclear if each item corresponds to a row or an element. But I would
> be in favor of rather liberal string parsing, so one could do
Why is it easier to decide if the items correspond to rows or elements
in
matrix( [ c for c in iterator ])
than it is in
matrix( ( c for c in iterator ) )
I agree that this problem arises if we would allow the c's themselves
to just be generic iterators, which would include strings.
(although you could argue that if no dimensions are given, matrix
should insist on [ [...], [...] , ... , [...]] rather than
interpreting [1,2,3] as [[1,2,3]]).
Of course, accepting iterators would be at odds with accepting strings
straight away, as in matrix("1,2,3\n4,5,6"), so we'd have to make a
choice between those two. Currently strings nor iterators are accepted
by a bare matrix. However, for related objects the choice has already
been made in favor of iterators:
sage: M22=MatrixSpace(Integers(),2,2)
sage: M22([1,2,3,4])
[1 2]
[3 4]
sage: M22( i for i in [1,2,3,4] )
[1 2]
[3 4]
sage: M22("1 2 3 4")
TypeError: entries has the wrong length
sage: M22("1234")
[1 2]
[3 4]
sage: matrix(QQ,2,2, (i for i in [1,2,3,4]) )
[1 2]
[3 4]
Especially the last example makes me hesitant about letting matrix
parse strings.
--
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