Documentation

calculate the dot product of a vector More...

 template ty dot (const array &x, const array &y) Scalar dot product between two vectors. More...

## Detailed Description

calculate the dot product of a vector

Scalar dot product between two vectors. Also referred to as the inner product.

This function returns the scalar product of two equal sized vectors or between a matrix and a vector. The second operand needs to be a vector in either case.

 
// compute scalar dot product of two vectors
float a[] = {1, 2, 3};
float b[] = {2, 3, 4};
array A(3,a);
array B(3,b);
print(A);
print(B);
print(dot(A,B));
 

The dot product between a matrix and a vector is defined in a similar fashion:

 
float a_buff[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1};
float b_buff[] = {0, 1, 2, 3};

array A(4, 3, a_buff);
array B(4, b_buff);
print(A);
print(B);
print(dot(A, B));
 

## Function Documentation

 array dot ( const array & x, const array & y )

Scalar dot product between two vectors.

Also referred to as the inner product.

 
// compute scalar dot product
array x = randu(100), y = randu(100);
print(dot(x,y));
 
Parameters
 [in] x [in] y
Returns
scalar dot product