6.2 Matrix arithmetic operators
Stan supports the basic matrix operations using infix, prefix and postfix operations. This section lists the operations supported by Stan along with their argument and result types.
6.2.1 Negation prefix operators
vector
operator-
(vector x)
The negation of the vector x.
Available since 2.0
row_vector
operator-
(row_vector x)
The negation of the row vector x.
Available since 2.0
matrix
operator-
(matrix x)
The negation of the matrix x.
Available since 2.0
T
operator-
(T x)
Vectorized version of operator-
. If T x
is a (possibly nested) array of
matrix types, -x
is the same shape array where each individual value is negated.
Available since 2.31
6.2.2 Infix matrix operators
vector
operator+
(vector x, vector y)
The sum of the vectors x and y.
Available since 2.0
row_vector
operator+
(row_vector x, row_vector y)
The sum of the row vectors x and y.
Available since 2.0
matrix
operator+
(matrix x, matrix y)
The sum of the matrices x and y
Available since 2.0
vector
operator-
(vector x, vector y)
The difference between the vectors x and y.
Available since 2.0
row_vector
operator-
(row_vector x, row_vector y)
The difference between the row vectors x and y
Available since 2.0
matrix
operator-
(matrix x, matrix y)
The difference between the matrices x and y
Available since 2.0
vector
operator*
(real x, vector y)
The product of the scalar x and vector y
Available since 2.0
row_vector
operator*
(real x, row_vector y)
The product of the scalar x and the row vector y
Available since 2.0
matrix
operator*
(real x, matrix y)
The product of the scalar x and the matrix y
Available since 2.0
vector
operator*
(vector x, real y)
The product of the scalar y and vector x
Available since 2.0
matrix
operator*
(vector x, row_vector y)
The product of the vector x and row vector y
Available since 2.0
row_vector
operator*
(row_vector x, real y)
The product of the scalar y and row vector x
Available since 2.0
real
operator*
(row_vector x, vector y)
The product of the row vector x and vector y
Available since 2.0
row_vector
operator*
(row_vector x, matrix y)
The product of the row vector x and matrix y
Available since 2.0
matrix
operator*
(matrix x, real y)
The product of the scalar y and matrix x
Available since 2.0
vector
operator*
(matrix x, vector y)
The product of the matrix x and vector y
Available since 2.0
matrix
operator*
(matrix x, matrix y)
The product of the matrices x and y
Available since 2.0
6.2.3 Broadcast infix operators
vector
operator+
(vector x, real y)
The result of adding y to every entry in the vector x
Available since 2.0
vector
operator+
(real x, vector y)
The result of adding x to every entry in the vector y
Available since 2.0
row_vector
operator+
(row_vector x, real y)
The result of adding y to every entry in the row vector x
Available since 2.0
row_vector
operator+
(real x, row_vector y)
The result of adding x to every entry in the row vector y
Available since 2.0
matrix
operator+
(matrix x, real y)
The result of adding y to every entry in the matrix x
Available since 2.0
matrix
operator+
(real x, matrix y)
The result of adding x to every entry in the matrix y
Available since 2.0
vector
operator-
(vector x, real y)
The result of subtracting y from every entry in the vector x
Available since 2.0
vector
operator-
(real x, vector y)
The result of adding x to every entry in the negation of the vector y
Available since 2.0
row_vector
operator-
(row_vector x, real y)
The result of subtracting y from every entry in the row vector x
Available since 2.0
row_vector
operator-
(real x, row_vector y)
The result of adding x to every entry in the negation of the row
vector y
Available since 2.0
matrix
operator-
(matrix x, real y)
The result of subtracting y from every entry in the matrix x
Available since 2.0
matrix
operator-
(real x, matrix y)
The result of adding x to every entry in negation of the matrix y
Available since 2.0
vector
operator/
(vector x, real y)
The result of dividing each entry in the vector x by y
Available since 2.0
row_vector
operator/
(row_vector x, real y)
The result of dividing each entry in the row vector x by y
Available since 2.0
matrix
operator/
(matrix x, real y)
The result of dividing each entry in the matrix x by y
Available since 2.0