flopscope.numpy.matvec
fnp.matvec(a, b, **kwargs)[flopscope source][numpy source]
Matrix-vector dot product of two arrays.
Adapted from NumPy docs np.matvec
Matrix-vector product. Cost = output_size * contracted_axis.
Given a matrix (or stack of matrices) in x1 and
a vector (or stack of vectors) in x2, the
matrix-vector product is defined as:
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 flops.vecmat(x2, x1.mT).)
Parameters
- x1, x2:array_like
Input arrays, scalars not allowed.
- out:ndarray, optional
A location into which the result is stored. If provided, it must have the broadcasted shape of
x1andx2with the summation axis removed. If not provided or None, a freshly-allocated array is used.- **kwargs
For other keyword-only arguments, see the ufunc docs.
Returns
- y:ndarray
The matrix-vector product of the inputs.
Raises
- :ValueError
If the last dimensions of
x1andx2are not the same size.If a scalar value is passed in.
See also
- we.flops.vecdot Vector-vector product.
- we.flops.vecmat Vector-matrix product.
- we.flops.matmul Matrix-matrix product.
- we.flops.einsum Einstein summation convention.
Examples
Rotate a set of vectors from Y to X along Z.
>>> a = flops.array([[0., 1., 0.],
... [-1., 0., 0.],
... [0., 0., 1.]])
>>> v = flops.array([[1., 0., 0.],
... [0., 1., 0.],
... [0., 0., 1.],
... [0., 6., 8.]])
>>> flops.matvec(a, v)
array([[ 0., -1., 0.],
[ 1., 0., 0.],
[ 0., 0., 1.],
[ 6., 0., 8.]])