---
title: "Multiplying Vectors or Matrices by Sparse Matrices"
canonical: "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/SparseMatrices/multiply.html"
source: "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/SparseMatrices/multiply.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": "Elementary Arithmetic", "source": "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/SparseMatrices/arithmetic.md"}
next: {"title": "Non-trivial Properties", "source": "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/SparseMatrices/non-trivial.md"}
intrinsics:
  - {"name": "*", "signature": "v * A: ModTupRng, MtrxSprs -> ModTupRng"}
  - {"name": "*", "signature": "V * A: Mtrx, MtrxSprs -> Mtrx"}
  - {"name": "MultiplyByTranspose", "signature": "MultiplyByTranspose(v, A): ModTupRng, MtrxSprs -> ModTupRng"}
  - {"name": "MultiplyByTranspose", "signature": "MultiplyByTranspose(V, A): Mtrx, MtrxSprs -> Mtrx"}
---

# Multiplying Vectors or Matrices by Sparse Matrices

These functions allow the multiplication of a normal (dense-representation) vector by a sparse matrix.

<a id="operation-op-times-modtuprng-mtrxsprs"></a>
## `v * A: ModTupRng, MtrxSprs -> ModTupRng`

<a id="operation-op-times-mtrx-mtrxsprs"></a>
## `V * A: Mtrx, MtrxSprs -> Mtrx`

Given a dense-representation vector $v$ or dense-representation matrix $V$ with $c$ columns, together with a sparse $c\times n$ matrix $A$, both over a ring $R$, return the product $v\cdot A$ or $V\cdot A$.

This is generally fast if $A$ is sparse and uses minimal memory.

<a id="function-multiplybytranspose-modtuprng-mtrxsprs"></a>
## `MultiplyByTranspose(v, A): ModTupRng, MtrxSprs -> ModTupRng`

<a id="function-multiplybytranspose-mtrx-mtrxsprs"></a>
## `MultiplyByTranspose(V, A): Mtrx, MtrxSprs -> Mtrx`

Given a dense-representation vector $v$ or dense-representation matrix $V$ with $c$ columns, together with a sparse $n\times c$ matrix $A$, both over a ring $R$, return the product of $v$ or $V$ by the transpose of $A$.

This is generally fast if $A$ is sparse, and is much faster than computing the transpose of $A$ first. For example, if the vector-matrix product $v\cdot A\cdot A^{tr}$ is required, then the function call `MultiplyByTranspose(v*A, A)` should be used to avoid forming the matrix $A\cdot A^{tr}$ which is usually dense. This product occurs in iterative algorithms such as Lanzcos.
