Linear Algebra¶
Matrix and vector products¶

cupy.
dot
(a, b, out=None)[source]¶ Returns a dot product of two arrays.
For arrays with more than one axis, it computes the dot product along the last axis of
a
and the secondtolast axis ofb
. This is just a matrix product if the both arrays are 2D. For 1D arrays, it uses their unique axis as an axis to take dot product over.Parameters:  a (cupy.ndarray) – The left argument.
 b (cupy.ndarray) – The right argument.
 out (cupy.ndarray) – Output array.
Returns: The dot product of
a
andb
.Return type: See also

cupy.
vdot
(a, b)[source]¶ Returns the dot product of two vectors.
The input arrays are flattened into 1D vectors and then it performs inner product of these vectors.
Parameters:  a (cupy.ndarray) – The first argument.
 b (cupy.ndarray) – The second argument.
Returns: Zerodimensional array of the dot product result.
Return type: See also

cupy.
inner
(a, b)[source]¶ Returns the inner product of two arrays.
It uses the last axis of each argument to take sum product.
Parameters:  a (cupy.ndarray) – The first argument.
 b (cupy.ndarray) – The second argument.
Returns: The inner product of
a
andb
.Return type: See also

cupy.
outer
(a, b, out=None)[source]¶ Returns the outer product of two vectors.
The input arrays are flattened into 1D vectors and then it performs outer product of these vectors.
Parameters:  a (cupy.ndarray) – The first argument.
 b (cupy.ndarray) – The second argument.
 out (cupy.ndarray) – Output array.
Returns: 2D array of the outer product of
a
andb
.Return type: See also

cupy.
tensordot
(a, b, axes=2)[source]¶ Returns the tensor dot product of two arrays along specified axes.
This is equivalent to compute dot product along the specified axes which are treated as one axis by reshaping.
Parameters:  a (cupy.ndarray) – The first argument.
 b (cupy.ndarray) – The second argument.
 axes –
 If it is an integer, then
axes
axes at the last ofa
and the first ofb
are used.  If it is a pair of sequences of integers, then these two
sequences specify the list of axes for
a
andb
. The corresponding axes are paired for sumproduct.
 If it is an integer, then
 out (cupy.ndarray) – Output array.
Returns: The tensor dot product of
a
andb
along the axes specified byaxes
.Return type: See also
Decompositions¶

cupy.linalg.
cholesky
(a)[source]¶ Cholesky decomposition.
Decompose a given twodimensional square matrix into
L * L.T
, whereL
is a lowertriangular matrix and.T
is a conjugate transpose operator. Note that in the current implementationa
must be a real matrix, and only float32 and float64 are supported.Parameters: a (cupy.ndarray) – The input matrix with dimension (N, N)
See also

cupy.linalg.
qr
(a, mode='reduced')[source]¶ QR decomposition.
Decompose a given twodimensional matrix into
Q * R
, whereQ
is an orthonormal andR
is an uppertriangular matrix.Parameters:  a (cupy.ndarray) – The input matrix.
 mode (str) – The mode of decomposition. Currently ‘reduced’,
‘complete’, ‘r’, and ‘raw’ modes are supported. The default mode
is ‘reduced’, and decompose a matrix
A = (M, N)
intoQ
,R
with dimensions(M, K)
,(K, N)
, whereK = min(M, N)
.
See also

cupy.linalg.
svd
(a, full_matrices=True, compute_uv=True)[source]¶ Singular Value Decomposition.
Factorizes the matrix
a
asu * np.diag(s) * v
, whereu
andv
are unitary ands
is an onedimensional array ofa
‘s singular values.Parameters:  a (cupy.ndarray) – The input matrix with dimension
(M, N)
.  full_matrices (bool) – If True, it returns U and V with dimensions
(M, M)
and(N, N)
. Otherwise, the dimensions of U and V are respectively(M, K)
and(K, N)
, whereK = min(M, N)
.  compute_uv (bool) – If True, it only returns singular values.
See also
 a (cupy.ndarray) – The input matrix with dimension
Norms etc.¶

cupy.
trace
(a, offset=0, axis1=0, axis2=1, dtype=None, out=None)[source]¶ Returns the sum along the diagonals of an array.
It computes the sum along the diagonals at
axis1
andaxis2
.Parameters:  a (cupy.ndarray) – Array to take trace.
 offset (int) – Index of diagonals. Zero indicates the main diagonal, a positive value an upper diagonal, and a negative value a lower diagonal.
 axis1 (int) – The first axis along which the trace is taken.
 axis2 (int) – The second axis along which the trace is taken.
 dtype – Data type specifier of the output.
 out (cupy.ndarray) – Output array.
Returns: The trace of
a
along axes(axis1, axis2)
.Return type: See also