We deliver solutions for the AI eraâcombining symbolic computation, data-driven insights and deep technology expertise.
SparseArray[{pos1v1,pos2v2,…}]
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.
DetailsConstruct a sparse matrix with values at only a few specified positions:
Convert it to an ordinary dense matrix:
Scope (7)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:
Represent a network with an adjacency matrix:
Solve a boundary-value problem using finite differences:
Properties & Relations (3) Possible Issues (8)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:
Wolfram Research (2003), SparseArray, Wolfram Language function, https://reference.wolfram.com/language/ref/SparseArray.html (updated 2021). TextWolfram Research (2003), SparseArray, Wolfram Language function, https://reference.wolfram.com/language/ref/SparseArray.html (updated 2021).
CMSWolfram Language. 2003. "SparseArray." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2021. https://reference.wolfram.com/language/ref/SparseArray.html.
APAWolfram 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: 11-July-2025 ]}
BibLaTeX@online{reference.wolfram_2025_sparsearray, organization={Wolfram Research}, title={SparseArray}, year={2021}, url={https://reference.wolfram.com/language/ref/SparseArray.html}, note=[Accessed: 11-July-2025 ]}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4