This is documentation for Mathematica 5, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)

Documentation / Mathematica / Built-in Functions / Lists and Matrices / List Construction /

Further Examples: SparseArray

Here are some rules suitable for constructing a sparse array.

In[1]:=

Here is a sparse array corresponding to rules.

In[2]:=

Out[2]=

This constructs the same sparse array using one rule.

In[3]:=

Out[3]=

In[4]:=

Out[4]=

This shows the ordinary representation of ss.

In[5]:=

Out[5]//MatrixForm=

This yields a sparse array in which unspecified elements are taken to have value instead of .

In[6]:=

Out[6]//MatrixForm=

The usual commands for matrices work with sparse arrays.

In[7]:=

Out[7]=

In[8]:=

Out[8]//MatrixForm=

This constructs a sparse array representing a banded matrix.

In[9]:=

Out[9]=

In[10]:=

Out[10]//MatrixForm=

The full form of a sparse array contains the necessary data stored in an efficient form.

In[11]:=

Out[11]//FullForm=

Evaluating the next two commands displays the structure of bb.

In[12]:=

In[13]:=

This shows the structure of another sparse array.

In[14]:=

This defines the function BlockDiagonalMatrix which creates a block diagonal matrix from a list of matrices. For another efficient implementation see the Further Examples for PadRight.

In[15]:=

Here are four matrices.

In[16]:=

Out[16]//MatrixForm=

In[17]:=

Out[17]//MatrixForm=

In[18]:=

Out[18]//MatrixForm=

In[19]:=

Out[19]//MatrixForm=

Here is the block diagonal matrix constructed from the four matrices.

In[20]:=

Out[20]//MatrixForm=

In[21]:=