# 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 second-to-last axis of b. This is just a matrix product if the both arrays are 2-D. For 1-D 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. The dot product of a and b. cupy.ndarray
cupy.vdot(a, b)[source]

Returns the dot product of two vectors.

The input arrays are flattened into 1-D vectors and then it performs inner product of these vectors.

Parameters: a (cupy.ndarray) – The first argument. b (cupy.ndarray) – The second argument. Zero-dimensional array of the dot product result. cupy.ndarray
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. The inner product of a and b. cupy.ndarray
cupy.outer(a, b, out=None)[source]

Returns the outer product of two vectors.

The input arrays are flattened into 1-D 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. 2-D array of the outer product of a and b. cupy.ndarray
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 of a and the first of b are used. If it is a pair of sequences of integers, then these two sequences specify the list of axes for a and b. The corresponding axes are paired for sum-product. out (cupy.ndarray) – Output array. The tensor dot product of a and b along the axes specified by axes. cupy.ndarray

## 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 and axis2.

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. The trace of a along axes (axis1, axis2). cupy.ndarray