vecdot#

ivy.vecdot(x1, x2, /, *, axis=-1, out=None)[source]#

Compute the (vector) dot product of two arrays.

Parameters:
  • x1 (Union[Array, NativeArray]) – first input array. Should have a numeric data type.

  • x2 (Union[Array, NativeArray]) – second input array. Must be compatible with x1 (see broadcasting). Should have a numeric data type.

  • axis (int, default: -1) – axis over which to compute the dot product. Must be an integer on the interval [-N, N), where N is the rank (number of dimensions) of the shape determined according to broadcasting. If specified as a negative integer, the function must determine the axis along which to compute the dot product by counting backward from the last dimension (where -1 refers to the last dimension). By default, the function must compute the dot product over the last axis. Default: -1.

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – if x1 and x2 are both one-dimensional arrays, a zero-dimensional containing the dot product; otherwise, a non-zero-dimensional array containing the dot products and having rank N-1, where N is the rank (number of dimensions) of the shape determined according to broadcasting. The returned array must have a data type determined by type-promotion.

Raises

  • if provided an invalid axis.

  • if the size of the axis over which to compute the dot product is not the same for both x1 and x2.

This function conforms to the Array API Standard. This docstring is an extension of the docstring in the standard.

Both the description and the type hints above assumes an array input for simplicity, but this function is nestable, and therefore also accepts ivy.Container instances in place of any of the arguments.

Examples

With ivy.Array input:

>>> x1 = ivy.array([1., 2., 3.])
>>> x2 = ivy.array([4., 5., 6.])
>>> dot_product = ivy.vecdot(x1, x2)
>>> print(dot_product)
ivy.array(32.)
>>> x1 = ivy.array([1., 2., 3.])
>>> x2 = ivy.array([1., .8, 4.])
>>> y = ivy.zeros(1)
>>> ivy.vecdot(x1, x2, out=y)
ivy.array(14.60000038)

With ivy.Container input:

>>> x1 = ivy.array([1., 2., 3.])
>>> x2 = ivy.Container(a=ivy.array([7., 8., 9.]), b=ivy.array([10., 11., 12.]))
>>> dot_product = ivy.vecdot(x1, x2, axis=0)
>>> print(dot_product)
{
    a: ivy.array(50.),
    b: ivy.array(68.)
}
Array.vecdot(self, x2, /, *, axis=-1, out=None)[source]#
Return type:

Array

Container.vecdot(self, x2, /, *, axis=-1, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#
Return type:

Container