# SparseArray internal structure [duplicate]

According to the documentation:

SparseArray is treated as a raw object by functions like AtomQ and for purposes of pattern matching.

Furthermore, they have specific functions to access and format subparts (Dimensions, ArrayRules, Normal, etc. ), though they also have an intricate internal structure. There is however little information on what exactly certain elements mean.

Some examples:

Normal@SparseArray[{2, 3, 4} -> {1, 1, 1}, {6}]
InputForm@SparseArray[{2, 3, 4} -> {1, 1, 1}, {6}]

 {0, 1, 1, 1, 0, 0}
SparseArray[Automatic, {6}, 0, {1, {{0, 3}, {{2}, {3}, {4}}}, {1, 1, 1}}]

x = SparseArray[{{i_, i_} -> 1, {3, 2} -> 2, {5, _} -> "x"}, {5, 4}, -1];
Normal@x
InputForm@x

   {{1, -1, -1, -1},
{-1, 1, -1, -1},
{-1, 2, 1, -1},
{-1, -1, -1, 1},
{"x", "x", "x", "x"}}

SparseArray[Automatic, {5, 4}, -1,
{1, {{0, 1, 2, 4, 5, 9}, {{1}, {2}, {3}, {2}, {4}, {4}, {3}, {2}, {1}}},
{1, 1, 1, 2, 1, "x", "x", "x", "x"}}]


For example, what is the purpose of the Automatic at the first position and what other values can be used instead of it?

• Hi István, I really appreciate the question! I searched around and found a relevant previous question How to interpret the FullForm of a SparseArray?. Do you think I should post my answer here or there? I do agree we should have a more structured, on-site answer on this topic! Mar 28, 2014 at 9:30
• @Silvia I guess my Q is indeed a duplicate, but considering how little attention Szabolcs's question got (this explains why I missed it when I checked for duplicates before posting), mine should be merged with his (or vice versa). Still, your image was quite descriptive, you could still add it as your own answer or add it to Leonid's CW. Mar 28, 2014 at 13:11
• Istvan, I've merged as you requested. Please also add the quote above and the example to Szabolcs's question as well, so that parts of Leonid's answer makes sense on that question as well :)
– rm -rf
Mar 28, 2014 at 15:20