Products
  • Wolfram|One

    The definitive Wolfram Language and notebook experience

  • Mathematica

    The original technical computing environment

  • Notebook Assistant + LLM Kit

    All-in-one AI assistance for your Wolfram experience

  • Compute Services
  • System Modeler
  • Finance Platform
  • Wolfram|Alpha Notebook Edition
  • Application Server
  • Enterprise Private Cloud
  • Wolfram Engine
  • Wolfram Player
  • Wolfram Cloud App
  • Wolfram Player App

More mobile apps

Core Technologies of Wolfram Products

  • Wolfram Language
  • Computable Data
  • Wolfram Notebooks
  • AI & Linguistic Understanding

Deployment Options

  • Wolfram Cloud
  • wolframscript
  • Wolfram Engine Community Edition
  • Wolfram LLM API
  • WSTPServer
  • Wolfram|Alpha APIs

From the Community

  • Function Repository
  • Community Paclet Repository
  • Example Repository
  • Neural Net Repository
  • Prompt Repository
  • Wolfram Demonstrations
  • Data Repository
  • Group & Organizational Licensing
  • All Products
Consulting & Solutions

We deliver solutions for the AI era—combining symbolic computation, data-driven insights and deep technical expertise

  • Data & Computational Intelligence
  • Model-Based Design
  • Algorithm Development
  • Wolfram|Alpha for Business
  • Blockchain Technology
  • Education Technology
  • Quantum Computation

Wolfram Consulting

Wolfram Solutions

  • Data Science
  • Artificial Intelligence
  • Biosciences
  • Healthcare Intelligence
  • Sustainable Energy
  • Control Systems
  • Enterprise Wolfram|Alpha
  • Blockchain Labs

More Wolfram Solutions

Wolfram Solutions For Education

  • Research Universities
  • Colleges & Teaching Universities
  • Junior & Community Colleges
  • High Schools
  • Educational Technology
  • Computer-Based Math

More Solutions for Education

  • Contact Us
Learning & Support

Get Started

  • Wolfram Language Introduction
  • Fast Intro for Programmers
  • Fast Intro for Math Students
  • Wolfram Language Documentation

More Learning

  • Highlighted Core Areas
  • Demonstrations
  • YouTube
  • Daily Study Groups
  • Wolfram Schools and Programs
  • Books

Grow Your Skills

  • Wolfram U

    Courses in computing, science, life and more

  • Community

    Learn, solve problems and share ideas.

  • Blog

    News, views and insights from Wolfram

  • Resources for

    Software Developers

Tech Support

  • Contact Us
  • Support FAQs
  • Support FAQs
  • Contact Us
Company
  • About Wolfram
  • Career Center
  • All Sites & Resources
  • Connect & Follow
  • Contact Us

Work with Us

  • Student Ambassador Initiative
  • Wolfram for Startups
  • Student Opportunities
  • Jobs Using Wolfram Language

Educational Programs for Adults

  • Summer School
  • Winter School

Educational Programs for Youth

  • Middle School Camp
  • High School Research Program
  • Computational Adventures

Read

  • Stephen Wolfram's Writings
  • Wolfram Blog
  • Wolfram Tech | Books
  • Wolfram Media
  • Complex Systems

Educational Resources

  • Wolfram MathWorld
  • Wolfram in STEM/STEAM
  • Wolfram Challenges
  • Wolfram Problem Generator

Wolfram Initiatives

  • Wolfram Science
  • Wolfram Foundation
  • History of Mathematics Project

Events

  • Stephen Wolfram Livestreams
  • Online & In-Person Events
  • Contact Us
  • Connect & Follow
Wolfram|Alpha
  • Your Account
  • User Portal
  • Wolfram Cloud
  • Products
    • Wolfram|One
    • Mathematica
    • Notebook Assistant + LLM Kit
    • Compute Services
    • System Modeler
    • Finance Platform
    • Wolfram|Alpha Notebook Edition
    • Application Server
    • Enterprise Private Cloud
    • Wolfram Engine
    • Wolfram Player
    • Wolfram Cloud App
    • Wolfram Player App

    More mobile apps

    • Core Technologies
      • Wolfram Language
      • Computable Data
      • Wolfram Notebooks
      • AI & Linguistic Understanding
    • Deployment Options
      • Wolfram Cloud
      • wolframscript
      • Wolfram Engine Community Edition
      • Wolfram LLM API
      • WSTPServer
      • Wolfram|Alpha APIs
    • From the Community
      • Function Repository
      • Community Paclet Repository
      • Example Repository
      • Neural Net Repository
      • Prompt Repository
      • Wolfram Demonstrations
      • Data Repository
    • Group & Organizational Licensing
    • All Products
  • Consulting & Solutions

    We deliver solutions for the AI era—combining symbolic computation, data-driven insights and deep technical expertise

    WolframConsulting.com

    Wolfram Solutions

    • Data Science
    • Artificial Intelligence
    • Biosciences
    • Healthcare Intelligence
    • Sustainable Energy
    • Control Systems
    • Enterprise Wolfram|Alpha
    • Blockchain Labs

    More Wolfram Solutions

    Wolfram Solutions For Education

    • Research Universities
    • Colleges & Teaching Universities
    • Junior & Community Colleges
    • High Schools
    • Educational Technology
    • Computer-Based Math

    More Solutions for Education

    • Contact Us
  • Learning & Support

    Get Started

    • Wolfram Language Introduction
    • Fast Intro for Programmers
    • Fast Intro for Math Students
    • Wolfram Language Documentation

    Grow Your Skills

    • Wolfram U

      Courses in computing, science, life and more

    • Community

      Learn, solve problems and share ideas.

    • Blog

      News, views and insights from Wolfram

    • Resources for

      Software Developers
    • Tech Support
      • Contact Us
      • Support FAQs
    • More Learning
      • Highlighted Core Areas
      • Demonstrations
      • YouTube
      • Daily Study Groups
      • Wolfram Schools and Programs
      • Books
    • Support FAQs
    • Contact Us
  • Company
    • About Wolfram
    • Career Center
    • All Sites & Resources
    • Connect & Follow
    • Contact Us

    Work with Us

    • Student Ambassador Initiative
    • Wolfram for Startups
    • Student Opportunities
    • Jobs Using Wolfram Language

    Educational Programs for Adults

    • Summer School
    • Winter School

    Educational Programs for Youth

    • Middle School Camp
    • High School Research Program
    • Computational Adventures

    Read

    • Stephen Wolfram's Writings
    • Wolfram Blog
    • Wolfram Tech | Books
    • Wolfram Media
    • Complex Systems
    • Educational Resources
      • Wolfram MathWorld
      • Wolfram in STEM/STEAM
      • Wolfram Challenges
      • Wolfram Problem Generator
    • Wolfram Initiatives
      • Wolfram Science
      • Wolfram Foundation
      • History of Mathematics Project
    • Events
      • Stephen Wolfram Livestreams
      • Online & In-Person Events
    • Contact Us
    • Connect & Follow
  • Wolfram|Alpha
  • Wolfram Cloud
  • Your Account
  • User Portal
Wolfram Language & System Documentation Center
SparseArray
  • See Also
    • ArrayRules
    • SparseArrayQ
    • Normal
    • Band
    • CoefficientArrays
    • ArrayPlot
    • Array
    • ConstantArray
    • NumericArray
    • Association
  • Related Guides
    • Sparse Arrays
    • Constructing Matrices
    • Matrices and Linear Algebra
    • Constructing Lists
    • Tensors
    • Graphs and Matrices
    • Operations on Vectors
    • Structure Matrices & Convolution Kernels
    • 3D Images
    • List Manipulation
    • Handling Arrays of Data
    • Systems Modeling
    • Linear and Nonlinear Filters
  • Workflows
    • Create a Matrix
  • Tech Notes
    • Constructing Lists
    • Sparse Arrays: Manipulating Lists
    • Sparse Arrays: Linear Algebra
    • Implementation notes: Numerical and Related Functions
    • See Also
      • ArrayRules
      • SparseArrayQ
      • Normal
      • Band
      • CoefficientArrays
      • ArrayPlot
      • Array
      • ConstantArray
      • NumericArray
      • Association
    • Related Guides
      • Sparse Arrays
      • Constructing Matrices
      • Matrices and Linear Algebra
      • Constructing Lists
      • Tensors
      • Graphs and Matrices
      • Operations on Vectors
      • Structure Matrices & Convolution Kernels
      • 3D Images
      • List Manipulation
      • Handling Arrays of Data
      • Systems Modeling
      • Linear and Nonlinear Filters
    • Workflows
      • Create a Matrix
    • Tech Notes
      • Constructing Lists
      • Sparse Arrays: Manipulating Lists
      • Sparse Arrays: Linear Algebra
      • Implementation notes: Numerical and Related Functions

SparseArray[{pos1v1,pos2v2,…}]

yields a sparse array with all elements zero except for values vi at positions posi.

SparseArray[list]

yields a sparse array version of list.

SparseArray[data,{d1,d2,…}]

yields a sparse array representing a d1×d2×… array.

SparseArray[data,dims,val]

yields a sparse array in which unspecified elements are taken to have value val.

Details
Details and Options Details and Options
Examples  
Basic Examples  
Scope  
Generalizations & Extensions  
Applications  
Properties & Relations  
Possible Issues  
Neat Examples  
See Also
Tech Notes
Related Guides
Related Workflows
Related Links
History
Cite this Page
BUILT-IN SYMBOL
  • See Also
    • ArrayRules
    • SparseArrayQ
    • Normal
    • Band
    • CoefficientArrays
    • ArrayPlot
    • Array
    • ConstantArray
    • NumericArray
    • Association
  • Related Guides
    • Sparse Arrays
    • Constructing Matrices
    • Matrices and Linear Algebra
    • Constructing Lists
    • Tensors
    • Graphs and Matrices
    • Operations on Vectors
    • Structure Matrices & Convolution Kernels
    • 3D Images
    • List Manipulation
    • Handling Arrays of Data
    • Systems Modeling
    • Linear and Nonlinear Filters
  • Workflows
    • Create a Matrix
  • Tech Notes
    • Constructing Lists
    • Sparse Arrays: Manipulating Lists
    • Sparse Arrays: Linear Algebra
    • Implementation notes: Numerical and Related Functions
    • See Also
      • ArrayRules
      • SparseArrayQ
      • Normal
      • Band
      • CoefficientArrays
      • ArrayPlot
      • Array
      • ConstantArray
      • NumericArray
      • Association
    • Related Guides
      • Sparse Arrays
      • Constructing Matrices
      • Matrices and Linear Algebra
      • Constructing Lists
      • Tensors
      • Graphs and Matrices
      • Operations on Vectors
      • Structure Matrices & Convolution Kernels
      • 3D Images
      • List Manipulation
      • Handling Arrays of Data
      • Systems Modeling
      • Linear and Nonlinear Filters
    • Workflows
      • Create a Matrix
    • Tech Notes
      • Constructing Lists
      • Sparse Arrays: Manipulating Lists
      • Sparse Arrays: Linear Algebra
      • Implementation notes: Numerical and Related Functions

SparseArray

SparseArray[{pos1v1,pos2v2,…}]

yields a sparse array with all elements zero except for values vi at positions posi.

SparseArray[list]

yields a sparse array version of list.

SparseArray[data,{d1,d2,…}]

yields a sparse array representing a d1×d2×… array.

SparseArray[data,dims,val]

yields a sparse array in which unspecified elements are taken to have value val.

Details

  • SparseArray is also known as sparse matrix.
  • Sparse arrays are typically used for efficient linear algebra where most of the entries are zero and for graph adjacency matrices.
  • A sparse array stores only the positions where there are nonzero values, but represents the full array:
  • The data can have the following forms:
  • rulesrules specifying positions and values.
    listconvert an array to SparseArray
    SymmetrizedArray[…]convert to SparseArray
    QuantityArray[…]convert to SparseArray of Quantity
    SparseArray[…]minimize the explicit nonzero elements
  • With s=SparseArray[rules,…] the following specifications can be used:
  • {{i1 1,…,i1 r}v1,{i2 1,…,i2 r}v2,…}s[[i1 1, …, i1 r]] has value v1, s[[i2 1, …, i2 r]] has value v2, etc.
    pattv{{i1 1,…,i1 r}v,{i2 1,…,i2 r}v,…} for all {ik 1,…,ik r} that matches the pattern patt
    patt:>vevaluate the value v for each matching position
    Band[…]valsspecify values for bands and subblocks
    {pos1,pos2,…}{v1,v2,…}equivalent to {pos1v1,pos2v2,…}
  • SparseArray conversions include:
  • Normal[SparseArray[…]]convert to the ordinary List array.
    SymmetrizedArray[SparseArray[…]]convert to a symmetrized array.
    ArrayRules[SparseArray[…]]give the list of rules {pos1->v1,pos2->v2,…}
  • A SparseArray object is a representation of an ordinary array, so many functions work like they would on the ordinary array. Examples include functions like Dimensions, Part, Plus and LinearSolve.
  • SparseArray[data,…] is always converted to an optimized standard form with structure SparseArray[Automatic,dims,val,…].
  • SparseArray is treated as a raw object by functions like AtomQ and for purposes of pattern matching.
  • By default, SparseArray takes unspecified elements val to be zero.
  • The elements in SparseArray need not be numeric, but cannot themselves be lists.
  • SparseArray[…][prop] gives the property prop of the SparseArray object. The following properties may be given:
  • "ImplicitValue"gives the value for elements that are not given explicitly
    "ExplicitLength"gives the number of explicit values
    "ExplicitValues"gives the list of explicit values
    "ExplicitPositions"gives the list of positions corresponding to the explicit values
    "ColumnIndices"gives the column indices from the compressed sparse row representation
    "RowPointers"gives the row pointer list from the compressed sparse row representation
    "BandWidth"gives the off-diagonal bandwidth for a sparse matrix
    "Density"gives the ratio of the number of explicit elements to the total number of elements

Examples

open all close all

Basic Examples  (1)

Construct a sparse matrix with values at only a few specified positions:

View it as a matrix:

Convert it to an ordinary dense matrix:

Scope  (7)

Make a large sparse vector:

Make a large sparse matrix:

Make a large sparse depth-3 array:

Construct a tridiagonal matrix using patterns for indices:

Construct a 10,000×10,000 version:

Make a sparse diagonal matrix:

This is equivalent to DiagonalMatrix:

Except that as a sparse matrix, it uses much less memory:

Construct a block diagonal matrix using rules with Band:

Convert an ordinary matrix into a sparse matrix:

Make a rank-4 sparse tensor with values at random positions:

ArrayRules produces the minimal list of rules needed to specify the SparseArray:

Many typical operations work with SparseArray objects as they would for equivalent lists:

Arithmetic works elementwise just as it does for lists:

Matrix products are done with Dot:

Many linear algebra functions are done efficiently with the sparse form:

Many other list commands work automatically:

Generalizations & Extensions  (2)

The unspecified elements can have any value:

Construct a sparse matrix with all machine-number values:

Construct a sparse matrix with exact integer values:

N[s] is the same as ns:

Applications  (4)

Create a list with a single nonzero element:

Plot a list of rules:

Represent a network with an adjacency matrix:

Solve a boundary-value problem using finite differences:

Properties & Relations  (3)

A SparseArray object is Equal to the corresponding ordinary list:

They are not SameQ because the expression structure is different:

For functions f that work with SparseArray objects, typically f[s]==f[Normal[s]]:

This includes all functions with the attribute Listable:

Convert linear expressions to SparseArray objects using CoefficientArrays:

Convert from SparseArray to expressions using Dot:

Possible Issues  (9)

If a position is repeated in the rule list for SparseArray, the first instance is used:

SparseArray objects can represent data too large to represent in normal form:

Using Normal will give a SystemException:

Sparse operations do not by default check for cancellation:

Use SparseArray to recompute the sparse structure:

The internal structure of a SparseArray representation is not unique and SameQ detects this:

Use SparseArray to recompute the sparse structure:

Note that Equal works as expected:

The internal structure of SparseArray representation is not unique and setting parts can change that structure:

Test if the SparseArray instances are the same:

Use SparseArray to recompute the sparse structure:

Note that Equal works as expected:

Operations with side effects may give different values when iterating over SparseArray:

With Reap and Sow you can see what elements are accessed:

For a SparseArray object, Part gives parts of the represented list:

The FullForm is a way of reconstructing the object from basic storage information:

A SparseArray object is treated as atomic for functions that do not work on the representation:

Cases does not work on the represented matrix:

You can often use the result of ArrayRules to get the information without expanding:

Even for a dense SparseArray there can be a division by 0:

The density of a SparseArray is 1:

Since a density 1. SparseArray is a very special case, making this work would be computationally excessively expansive. In this case, the use of Normal is justified as the matrix is dense:

Neat Examples  (1)

The Game of Life:

See Also

ArrayRules  SparseArrayQ  Normal  Band  CoefficientArrays  ArrayPlot  Array  ConstantArray  NumericArray  Association

Function Repository: SparseAssociation

Tech Notes

    ▪
  • Constructing Lists
  • ▪
  • Sparse Arrays: Manipulating Lists
  • ▪
  • Sparse Arrays: Linear Algebra
  • ▪
  • Implementation notes: Numerical and Related Functions

Related Guides

    ▪
  • Sparse Arrays
  • ▪
  • Constructing Matrices
  • ▪
  • Matrices and Linear Algebra
  • ▪
  • Constructing Lists
  • ▪
  • Tensors
  • ▪
  • Graphs and Matrices
  • ▪
  • Operations on Vectors
  • ▪
  • Structure Matrices & Convolution Kernels
  • ▪
  • 3D Images
  • ▪
  • List Manipulation
  • ▪
  • Handling Arrays of Data
  • ▪
  • Systems Modeling
  • ▪
  • Linear and Nonlinear Filters

Related Workflows

    Related Workflows
    ▪
  • Create a Matrix

Related Links

  • An Elementary Introduction to the Wolfram Language : Arrays, or Lists of Lists

History

Introduced in 2003 (5.0) | Updated in 2007 (6.0) ▪ 2021 (13.0)

Wolfram Research (2003), SparseArray, Wolfram Language function, https://reference.wolfram.com/language/ref/SparseArray.html (updated 2021).

Text

Wolfram Research (2003), SparseArray, Wolfram Language function, https://reference.wolfram.com/language/ref/SparseArray.html (updated 2021).

CMS

Wolfram Language. 2003. "SparseArray." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2021. https://reference.wolfram.com/language/ref/SparseArray.html.

APA

Wolfram Language. (2003). SparseArray. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/SparseArray.html

BibTeX

@misc{reference.wolfram_2025_sparsearray, author="Wolfram Research", title="{SparseArray}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/SparseArray.html}", note=[Accessed: 01-May-2026]}

BibLaTeX

@online{reference.wolfram_2025_sparsearray, organization={Wolfram Research}, title={SparseArray}, year={2021}, url={https://reference.wolfram.com/language/ref/SparseArray.html}, note=[Accessed: 01-May-2026]}

Top
Introduction for Programmers
Introductory Book
Wolfram Function Repository | Wolfram Data Repository | Wolfram Data Drop | Wolfram Language Products
Top
  • Products
  • Wolfram|One
  • Mathematica
  • Notebook Assistant + LLM Kit
  • Compute Services
  • System Modeler

  • Wolfram|Alpha Notebook Edition
  • Wolfram|Alpha Pro
  • Mobile Apps

  • Wolfram Engine
  • Wolfram Player

  • Volume & Site Licensing
  • Server Deployment Options
  • Consulting
  • Wolfram Consulting
  • Repositories
  • Data Repository
  • Function Repository
  • Community Paclet Repository
  • Neural Net Repository
  • Prompt Repository

  • Wolfram Language Example Repository
  • Notebook Archive
  • Wolfram GitHub
  • Learning
  • Wolfram U
  • Wolfram Language Documentation
  • Webinars & Training
  • Educational Programs

  • Wolfram Language Introduction
  • Fast Introduction for Programmers
  • Fast Introduction for Math Students
  • Books

  • Wolfram Community
  • Wolfram Blog
  • Public Resources
  • Wolfram|Alpha
  • Wolfram Problem Generator
  • Wolfram Challenges

  • Computer-Based Math
  • Computational Thinking
  • Computational Adventures

  • Demonstrations Project
  • Wolfram Data Drop
  • MathWorld
  • Wolfram Science
  • Wolfram Media Publishing
  • Customer Resources
  • Store
  • Product Downloads
  • User Portal
  • Your Account
  • Organization Access

  • Support FAQ
  • Contact Support
  • Company
  • About Wolfram
  • Careers
  • Contact
  • Events
Wolfram Community Wolfram Blog
Legal & Privacy Policy
WolframAlpha.com | WolframCloud.com
© 2026 Wolfram
© 2026 Wolfram | Legal & Privacy Policy |
English