---
title: "Conversion to and from Dense Matrices"
canonical: "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/SparseMatrices/conversion.html"
source: "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/SparseMatrices/conversion.md"
part: "Matrices and Linear Algebra"
chapter: "Sparse Matrices"
breadcrumbs:
  - {"title": "Magma Handbook", "source": "https://docs.magma-maths.org/v2.30-1/index.md"}
  - {"title": "Matrices and Linear Algebra", "source": "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/index-matrices-linear-algebra.md"}
  - {"title": "Sparse Matrices", "source": "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/SparseMatrices/index-sparse-matrices.md"}
prev: {"title": "Building Block Matrices", "source": "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/SparseMatrices/join.md"}
next: {"title": "Changing Ring", "source": "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/SparseMatrices/change-ring.md"}
intrinsics:
  - {"name": "Matrix", "signature": "Matrix(A): MtrxSprs -> Mtrx"}
  - {"name": "SparseMatrix", "signature": "SparseMatrix(A): Mtrx -> MtrxSprs"}
---

# Conversion to and from Dense Matrices

The following functions convert between sparse matrices and normal (dense-representation) matrices.

<a id="function-smat-matrix"></a>
## `Matrix(A): MtrxSprs -> Mtrx`

Given a sparse matrix $A$, return the normal (dense-representation) matrix equal to $A$. This function should only be used if the size of $A$ is reasonably small since otherwise the amount of memory needed to represent the dense-representation matrix may be huge. Printing the result of this operation is a convenient way to display $A$ as a normal (dense) matrix if $A$ is small.

<a id="function-sparsematrix-mtrx"></a>
## `SparseMatrix(A): Mtrx -> MtrxSprs`

Given a normal (dense-representation) matrix $A$, return the sparse matrix equal to $A$. Note that if there is a fast algorithm available for the sparse matrix type, there is no need to convert a dense-representation matrix to the sparse matrix type first and then to use that algorithm, since Magma does this automatically.
