Sage does not (as far as I know) have a matrix constructor from a
string. You could write your own. there is an easy but dangerous way
to do that:
matrix(eval("[[1,2],[3,4]]"))
--dangerous as the user could enter any string and on running eval it
could have nasty side-effects (such as a system call to delete all
your files).
This does work:
matrix(pari("[[1,2],[3,4]]").sage())
by using the string parsing from the pari library. That might work
for you -- the entries would not have to be integers.
John Cremona
On 3 January 2014 07:18, Eileen Ee <[email protected]> wrote:
> Hi everyone,
>
> I have a program that requires some user inputs. I know raw_input([...]) can
> be used for string inputs and int(raw_input([...])) for integer inputs but I
> also need a matrix input from users. Is there anyone who can help me with
> this?
>
> I thought of asking the user to input a list, for eg.
>
> in program: g = raw_input(matrix input: ')
> G = matrix(g)
>
> sage: matrix input: [[2,2],[3,3]]
>
> for the matrix [2 2]
> [3 3]
>
> but the raw_input function takes my input as a string, ie g =
> "[[2,2],[3,3]]" hence cannot construct the matrix G...I know if those are
> typed into the console, it will work...
>
> sage: g = [[2,2],[3,3]]
> sage: G = matrix(g)
> sage: G
> [2 2]
> [3 3]
>
> But the raw_input function will read it as a string "[[2,2],[3,3]]" and will
> not work... Is there some easy way for user to input a matrix?....
>
> Thanks in advance!
> Eileen
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sage-support.
> For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/groups/opt_out.