numpy.vecdot#

numpy.vecdot(x1,x2,/,out=None,*,casting='same_kind',order='K',dtype=None,subok=True[,signature,axes,axis])=<ufunc'vecdot'>#

Vector dot product of two arrays.

Let\(\mathbf{a}\) be a vector inx1 and\(\mathbf{b}\) bea corresponding vector inx2. The dot product is defined as:

\[\mathbf{a} \cdot \mathbf{b} = \sum_{i=0}^{n-1} \overline{a_i}b_i\]

where the sum is over the last dimension (unlessaxis is specified) andwhere\(\overline{a_i}\) denotes the complex conjugate if\(a_i\)is complex and the identity otherwise.

New in version 2.0.0.

Parameters:
x1, x2array_like

Input arrays, scalars not allowed.

outndarray, optional

A location into which the result is stored. If provided, it must havethe broadcasted shape ofx1 andx2 with the last axis removed.If not provided or None, a freshly-allocated array is used.

**kwargs

For other keyword-only arguments, see theufunc docs.

Returns:
yndarray

The vector dot product of the inputs.This is a scalar only when both x1, x2 are 1-d vectors.

Raises:
ValueError

If the last dimension ofx1 is not the same size asthe last dimension ofx2.

If a scalar value is passed in.

See also

vdot

same but flattens arguments first

matmul

Matrix-matrix product.

vecmat

Vector-matrix product.

matvec

Matrix-vector product.

einsum

Einstein summation convention.

Examples

>>>importnumpyasnp

Get the projected size along a given normal for an array of vectors.

>>>v=np.array([[0.,5.,0.],[0.,0.,10.],[0.,6.,8.]])>>>n=np.array([0.,0.6,0.8])>>>np.vecdot(v,n)array([ 3.,  8., 10.])
On this page