12.07.2015 Views

Sage Reference Manual: Matrices and Spaces of Matrices

Sage Reference Manual: Matrices and Spaces of Matrices

Sage Reference Manual: Matrices and Spaces of Matrices

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTERTWOMATRIX CONSTRUCTORclass sage.matrix.constructor.MatrixFactoryBases: objectCreate a matrix.This implements the matrix constructor:sage: matrix([[1,2],[3,4]])[1 2][3 4]It also contains methods to create special types <strong>of</strong> matrices, see matrix.[tab] for more options. For example:sage: matrix.identity(2)[1 0][0 1]INPUT:The matrix comm<strong>and</strong> takes the entries <strong>of</strong> a matrix, optionally preceded by a ring <strong>and</strong> the dimensions <strong>of</strong> thematrix, <strong>and</strong> returns a matrix.The entries <strong>of</strong> a matrix can be specified as a flat list <strong>of</strong> elements, a list <strong>of</strong> lists (i.e., a list <strong>of</strong> rows), a list <strong>of</strong><strong>Sage</strong> vectors, a callable object, or a dictionary having positions as keys <strong>and</strong> matrix entries as values (see theexamples). If you pass in a callable object, then you must specify the number <strong>of</strong> rows <strong>and</strong> columns. You cancreate a matrix <strong>of</strong> zeros by passing an empty list or the integer zero for the entries. To construct a multiple <strong>of</strong> theidentity (cI), you can specify square dimensions <strong>and</strong> pass in c. Calling matrix() with a <strong>Sage</strong> object may returnsomething that makes sense. Calling matrix() with a NumPy array will convert the array to a matrix.The ring, number <strong>of</strong> rows, <strong>and</strong> number <strong>of</strong> columns <strong>of</strong> the matrix can be specified by setting the ring, nrows, orncols parameters or by passing them as the first arguments to the function in the order ring, nrows, ncols. Thering defaults to ZZ if it is not specified or cannot be determined from the entries. If the numbers <strong>of</strong> rows <strong>and</strong>columns are not specified <strong>and</strong> cannot be determined, then an empty 0x0 matrix is returned.•ring - the base ring for the entries <strong>of</strong> the matrix.•nrows - the number <strong>of</strong> rows in the matrix.•ncols - the number <strong>of</strong> columns in the matrix.•sparse - create a sparse matrix. This defaults to True when the entries are given as a dictionary, otherwisedefaults to False.OUTPUT:a matrix15

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!