Documentation
Mathematica
Built-in Functions
Advanced Documentation
Linear Algebra
Matrix and Tensor Operations

Vectors and Tensors
In addition to supporting matrices, Mathematica supports vectors and tensors. All of these are built from lists. As described in the Introduction, Mathematica uses the term tensor to refer to generalized matrices. All the operations for building matrices can be generalized to work for vectors and tensors. Mathematica vectors have one level of list. Here a vector is constructed.
In[1]:=
Out[1]=
In addition, there are a number of functions that generate vectors.

Functions for generating vectors.
One very efficient way to generate a vector is to use the Mathematica function Range. This generates a vector of integers.
In[2]:=
Out[2]=
This generates a vector of reals, starting with 1., incrementing in 0.1, and ending at 4.
In[3]:=
Out[3]=
Table can also be used to programmatically construct a vector; this is particularly useful if you want to execute a function to determine the elements of the vector.
In[4]:=
Out[4]=
The operations and functions discussed in previous sections have equivalent versions for vectors.
In[5]:=
Out[5]=
In[6]:=
Out[6]=
In[7]:=
Out[8]=
It should be noted that Mathematica has no concept of a row or a column vector; a vector has a single index that can be used to reference an element of the vector.
Tensors can also be built using the Table command. Here, three iterators are used to generate a 2
3
4 tensor.
In[9]:=
Out[9]=
One can extract an element by using Part with three indices.
In[10]:=
Out[10]=
Testing Vectors and Tensors
Mathematica provides a number of functions for testing vectors and tensors and extracting size information.

Functions for testing the structure of vectors, matrices, and arrays.
If you want to test that an expression is a matrix you can use the predicate MatrixQ.
In[1]:=
Out[1]=
In addition to MatrixQ, VectorQ and ArrayQ are useful for testing vectors and tensors.
In[2]:=
Out[2]=
In[3]:=
Out[3]=
ArrayQ can also take a rank argument to test the depth of the array.
In[4]:=
Out[4]=
ArrayQ also takes a third argument that tests each element. In this example the result is False because not all the elements are NumberQ.
In[5]:=
Out[5]=
The command Dimensions is useful for extracting size information.
In[6]:=
Out[6]=
Dimensions returns a list of length 2 when the input is a matrix, stating that two indices are used to reference any element in the matrix. Another way to test the number of indices required to reference elements is with ArrayDepth. In this example the result is 2.
In[7]:=
Out[7]=
To compare if the elements of two tensors are equal it is possible to use Equal, typically entered using a == short-cut notation. For example, comparing a tensor with itself returns True.
In[8]:=
Out[9]=
Equal uses the value of numbers so it can be used to compare integer and real values.
In[10]:=
Out[10]=
If the structure of two objects does not match they are not equal.
In[11]:=
Out[11]=