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

List


is a list of elements.
  • Lists are very general objects that represent collections of expressions.
  • Functions with attribute Listable are automatically "threaded" over lists, so that they act separately on each list element. Most built-in mathematical functions are Listable.
  • represents a vector.
  • represents a matrix.
  • Nested lists can be used to represent tensors.
In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]//FullForm=
A vector is a list of nonlist elements:
Many operations work on vectors, like Dot and Norm:
A matrix is a list of vectors of equal length:
Many operations work with matrices, like Dot, Transpose, and Det:
A rectangular array is represented by nested lists with consistent dimensions:
Many operations work on arrays of any depth, like Dot and Fourier:
The three-dimensional discrete Fourier transform:
Ragged arrays that are not rectangular can also be used:
Many structural functions will work with ragged arrays:
If the elements are at the same depth, you can use PadRight to make a rectangular array:
Range constructs a list consisting of a range of values:
Array constructs lists using a function:
When given multiple dimensions, matrices or deeper arrays are constructed:
Table constructs lists using an expression and an iterator:
When given multiple iterators, matrices and arrays can be constructed:
Functional commands like NestList create lists of the results:
To construct a list when the length is not known ahead of time, Sow and Reap are efficient:
Some trials of rolling a die until the same number comes up twice in a row:
Add two vectors:
Scalar multiple:
Sine of a vector:
Scalar multiple of a matrix:
Matrix plus a vector adds the component of the vector to the rows of the matrix:
Function applied element-wise to a matrix:
Any function that has the Listable attribute will thread over lists element-wise:
Apply makes the elements of a list the arguments of a function:
If you have a nested list, applying at level 1 gives a list f applied to the sublists:
Map applies a function to the elements of a list:
For a nested list, Map can apply f at any level or multiple levels:
Do, Product, Sum, and Table can iterate over a list:
Part can be used to get elements of lists:
You can get multiple parts by specifying a list of parts:
Or by using Span:
Use Outer to apply a function to elements of multiple lists:
Complement, Union, and Intersection treat List as a set:
Construct various combinatorial structures using Subsets, Tuples, and IntegerPartitions:
Many commands use as a specification of variable range:
Many commands use for a collection of variables:
A list of rules is returned as a solution by many solving commands:
You can use the values of the results with ReplaceAll:
When multiple solutions are possible, the result is a list of rule lists:
When a list of rule lists is used in ReplaceAll, you get a list of results:
Even if there is only one solution, the extra List is used for consistent structure:
Lists are very good for holding data since the elements can be anything:
Sine of successive squares:
Plot the data:
Data from a function sampled at points in two dimensions:
A piecewise polynomial that interpolates the data:
Plot the data directly:
A SparseArray represents a list:
They are Equal:
They can be equivalently used in many commands:
They are not identical because the representation is different:
Normal[slist] gives the List representation:
New in 1