08.02.2015 Views

Sage Reference Manual: Matrices and Spaces of Matrices - Mirrors

Sage Reference Manual: Matrices and Spaces of Matrices - Mirrors

Sage Reference Manual: Matrices and Spaces of Matrices - Mirrors

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.

<strong>Sage</strong> <strong>Reference</strong> <strong>Manual</strong>: <strong>Matrices</strong> <strong>and</strong> <strong>Spaces</strong> <strong>of</strong> <strong>Matrices</strong>, Release 6.1.1<br />

sage: A.new_matrix()<br />

[0.000000000000000 0.000000000000000 0.000000000000000]<br />

[0.000000000000000 0.000000000000000 0.000000000000000]<br />

sage: A.new_matrix().parent()<br />

Full MatrixSpace <strong>of</strong> 2 by 3 dense matrices over Real Field with 53 bits <strong>of</strong> precision<br />

numpy(dtype=None)<br />

Return the Numpy matrix associated to this matrix.<br />

INPUT:<br />

•dtype - The desired data-type for the array. If not given, then the type will be determined as the<br />

minimum type required to hold the objects in the sequence.<br />

EXAMPLES:<br />

sage: a = matrix(3,range(12))<br />

sage: a.numpy()<br />

array([[ 0, 1, 2, 3],<br />

[ 4, 5, 6, 7],<br />

[ 8, 9, 10, 11]])<br />

sage: a.numpy(’f’)<br />

array([[ 0., 1., 2., 3.],<br />

[ 4., 5., 6., 7.],<br />

[ 8., 9., 10., 11.]], dtype=float32)<br />

sage: a.numpy(’d’)<br />

array([[ 0., 1., 2., 3.],<br />

[ 4., 5., 6., 7.],<br />

[ 8., 9., 10., 11.]])<br />

sage: a.numpy(’B’)<br />

array([[ 0, 1, 2, 3],<br />

[ 4, 5, 6, 7],<br />

[ 8, 9, 10, 11]], dtype=uint8)<br />

Type numpy.typecodes for a list <strong>of</strong> the possible typecodes:<br />

sage: import numpy<br />

sage: sorted(numpy.typecodes.items())<br />

[(’All’, ’bhilqpBHILQPefdgFDGSUVOMm’), (’AllFloat’, ’efdgFDG’), (’AllInteger’, ’bBhHiIlLqQp<br />

Alternatively, numpy automatically calls this function (via the magic __array__() method) to convert<br />

<strong>Sage</strong> matrices to numpy arrays:<br />

sage: import numpy<br />

sage: b=numpy.array(a); b<br />

array([[ 0, 1, 2, 3],<br />

[ 4, 5, 6, 7],<br />

[ 8, 9, 10, 11]])<br />

sage: b.dtype<br />

dtype(’int32’) # 32-bit<br />

dtype(’int64’) # 64-bit<br />

sage: b.shape<br />

(3, 4)<br />

row(i, from_list=False)<br />

Return the i‘th row <strong>of</strong> this matrix as a vector.<br />

This row is a dense vector if <strong>and</strong> only if the matrix is a dense matrix.<br />

INPUT:<br />

108 Chapter 6. Base class for matrices, part 1

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

Saved successfully!

Ooh no, something went wrong!