flopscope.

flopscope.numpy.vecmat

fnp.vecmat(a, b, **kwargs)[flopscope source][numpy source]

Vector-matrix dot product of two arrays.

Adapted from NumPy docs np.vecmat

Areacore
Typecounted
NumPy Refnp.vecmat
Cost
numel(output)\text{numel}(\text{output})
Flopscope Context

Vector-matrix product. Cost = output_size * contracted_axis.

Given a vector (or stack of vector) v\mathbf{v} in x1 and a matrix (or stack of matrices) A\mathbf{A} in x2, the vector-matrix product is defined as:

bA=i=0n1viAij\mathbf{b} \cdot \mathbf{A} = \sum_{i=0}^{n-1} \overline{v_i}A_{ij}

where the sum is over the last dimension of x1 and the one-but-last dimensions in x2 (unless axes is specified) and where vi\overline{v_i} denotes the complex conjugate if vv is complex and the identity otherwise. (For a non-conjugated vector-matrix product, use flops.matvec(x2.mT, x1).)

Added in version 2.2.0.

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 x1 and x2 with 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 vector-matrix product of the inputs.

Raises

:ValueError

If the last dimensions of x1 and the one-but-last dimension of x2 are not the same size.

If a scalar value is passed in.

See also

Examples

Project a vector along X and Y.

>>> v = flops.array([0., 4., 2.])
>>> a = flops.array([[1., 0., 0.],
... [0., 1., 0.],
... [0., 0., 0.]])
>>> flops.vecmat(v, a)
array([ 0.,  4., 0.])