SparseArrayQ[s]
yields True if s is a valid SparseArray object and False otherwise.
SparseArrayQ
SparseArrayQ[s]
yields True if s is a valid SparseArray object and False otherwise.
Examples
open all close allBasic Examples (1)
Test whether an object is a valid SparseArray object:
SparseArray[{{1, 2} -> 3, {4, 5} -> 6}]SparseArrayQ[%]Scope (4)
SparseArrayQ works with sparse vectors:
SparseArrayQ[SparseArray[{1, 0, 2}]]SparseArrayQ works with sparse arrays of any depth:
s = SparseArray[ConstantArray[1, 100] -> 2.]SparseArrayQ[%]SparseArrayQ works with large sparse arrays:
SparseArrayQ[IdentityMatrix[10 ^ 6, SparseArray]]SparseArrayQ gives False for anything that is not a SparseArray:
SparseArrayQ[x]SparseArrayQ[SparseArray[{1, {2, 3}}]]Properties & Relations (2)
When SparseArrayQ is True, ArrayQ will also be True but not the converse:
d = {{1., 0., 2.}, {0., 3., 0.}};
s = SparseArray[d];| | |
| --------- | --------------- |
| ArrayQ[d] | SparseArrayQ[d] |
| ArrayQ[s] | SparseArrayQ[s] |SparseArrayQ is equivalent to (ArrayQ[#] && MatchQ[#,_SparseArray])&:
test = (ArrayQ[#] && MatchQ[#, _SparseArray])&;d = {{1., 0., 2.}, {0., 3., 0.}};
s = SparseArray[d];test[d] === SparseArrayQ[d]test[s] === SparseArrayQ[s]See Also
History
Text
Wolfram Research (2021), SparseArrayQ, Wolfram Language function, https://reference.wolfram.com/language/ref/SparseArrayQ.html.
CMS
Wolfram Language. 2021. "SparseArrayQ." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/SparseArrayQ.html.
APA
Wolfram Language. (2021). SparseArrayQ. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/SparseArrayQ.html
BibTeX
@misc{reference.wolfram_2026_sparsearrayq, author="Wolfram Research", title="{SparseArrayQ}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/SparseArrayQ.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_sparsearrayq, organization={Wolfram Research}, title={SparseArrayQ}, year={2021}, url={https://reference.wolfram.com/language/ref/SparseArrayQ.html}, note=[Accessed: 13-June-2026]}