dpnp.matvec
- dpnp.matvec(x1, x2, /, out=None, *, casting='same_kind', order='K', dtype=None, subok=True, signature=None, axes=None, axis=None)
Matrix-vector dot product of two arrays.
Given a matrix (or stack of matrices) \(\mathbf{A}\) in x1 and a vector (or stack of vectors) \(\mathbf{v}\) in x2, the matrix-vector product is defined as:
\[\mathbf{A} \cdot \mathbf{b} = \sum_{i=0}^{n-1} A_{ij}v_j\]where the sum is over the last dimensions in x1 and x2 (unless axes is specified). (For a matrix-vector product with the vector conjugated, use
dpnp.vecmat(x2, x1.mT)
.)For full documentation refer to
numpy.matvec
.- Parameters:
x1 ({dpnp.ndarray, usm_ndarray}) -- First input array.
x2 ({dpnp.ndarray, usm_ndarray}) -- Second input array.
out ({None, dpnp.ndarray, usm_ndarray}, optional) --
A location into which the result is stored. If provided, it must have the broadcasted shape of x1 and x2 with the summation axis removed. If not provided or
None
, a freshly-allocated array is used.Default:
None
.dtype ({None, str, dtype object}, optional) --
Type to use in computing the matrix product. By default, the returned array will have data type that is determined by considering Promotion Type Rule and device capabilities.
Default:
None
.casting ({"no", "equiv", "safe", "same_kind", "unsafe"}, optional) --
Controls what kind of data casting may occur.
Default:
"same_kind"
.order ({"C", "F", "A", "K", None}, optional) --
Memory layout of the newly output array, if parameter out is
None
.Default:
"K"
.axes ({None, list of tuples}, optional) --
A list of tuples with indices of axes the matrix-vector product should operate on. For instance, for the signature of
(i,j),(j)->(i)
, the base elements are 2d matrices and 1d vectors, where the matrices are assumed to be stored in the last two axes of the first argument, and the vectors in the last axis of the second argument. The corresponding axes keyword would be[(-2, -1), (-1,), (-1,)]
.Default:
None
.
- Returns:
out -- Returns the matrix-vector product of the inputs.
- Return type:
dpnp.ndarray
Limitations
Keyword arguments subok, and signature are only supported with their default values. Otherwise
NotImplementedError
exception will be raised.See also
dpnp.vecdot
Vector-vector product..
dpnp.vecmat
Vector-matrix product.
dpnp.matmul
Matrix-matrix product.
dpnp.einsum
Einstein summation convention.
Examples
Rotate a set of vectors from Y to X along Z.
>>> import dpnp as np >>> a = np.array([[0., 1., 0.], ... [-1., 0., 0.], ... [0., 0., 1.]]) >>> v = np.array([[1., 0., 0.], ... [0., 1., 0.], ... [0., 0., 1.], ... [0., 6., 8.]]) >>> np.matvec(a, v) array([[ 0., -1., 0.], [ 1., 0., 0.], [ 0., 0., 1.], [ 6., 0., 8.]])