Ask Your Question
1

Define a big matrix in Sage

asked 2016-02-06 20:47:22 +0200

Dianbin Bao gravatar image

updated 2016-02-07 14:54:27 +0200

Hi all,

I would like to define a big matrix E (130$\times$ 30) with entries being a list like E[11,1] = [x, [1,-2]];

E[14,1] = [x, [1,-1,-2,1]]; or 0. These entries are stored in a separate file which is readable by Pari but not Sage.

How do I define it by Sage?

edit retag flag offensive close merge delete

Comments

Can you make the info a dictionary, which is an easy way to define the matrix? http://doc.sagemath.org/html/en/refer...

kcrisman gravatar imagekcrisman ( 2016-02-07 00:46:36 +0200 )edit

To people who has similar problems: One can unravel multidimensional list to one dimensional list and then input Sage.

Dianbin Bao gravatar imageDianbin Bao ( 2016-02-11 16:48:26 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-02-08 15:00:42 +0200

vdelecroix gravatar image

updated 2016-02-08 15:01:07 +0200

A Sage matrix must have its entries being element of some ring. In other words you can not have a matrix of lists. However it is perfectly fine to have a 2d array (aka a "list of lists").

sage: l = [[1, [2,3]], [2, [5,4]]]
sage: print l
[[1, [2, 3]], [2, [5, 4]]]

To execute some code contained in a string you might use the "eval" or "sage_eval" command

sage: my_string = "[[1, [2,3]], [2, [5,4]]]"
sage: sage_eval(my_string)   # run the Python code from my_string
[[1, [2, 3]], [2, [5, 4]]]

And to read the content of the file these are the standard Python commands open/close

sage: f = open("my_file.data")   # open the file
sage: string = f.read()          # read what is inside (result is a string)
sage: f.close()                  # close the file
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

1 follower

Stats

Asked: 2016-02-06 20:47:22 +0200

Seen: 416 times

Last updated: Feb 08 '16