vecdot(x, y)

For any iterable containers x and y (including arrays of any dimension) of numbers (or any element type for which dot is defined), compute the Euclidean dot product (the sum of dot(x[i],y[i])) as if they were vectors.


  1. Compute the dot product of two arrays:

    julia> x = [1, 2, 3];
    julia> y = [4, 5, 6];
    julia> vecdot(x, y)

    This example calculates the dot product of the arrays x and y.

  2. Calculate the dot product of two matrices:

    julia> A = [1 2; 3 4];
    julia> B = [5 6; 7 8];
    julia> vecdot(A, B)

    It computes the dot product of the matrices A and B.

  3. Compute dot product of complex vectors:
    julia> x = [1+2im, 3+4im];
    julia> y = [5+6im, 7+8im];
    julia> vecdot(x, y)
    70 + 100im

    The function can handle complex numbers and compute the dot product accordingly.

Common mistake example:

julia> x = [1, 2, 3];
julia> y = [4, 5];
julia> vecdot(x, y)
ERROR: DimensionMismatch("dot product arguments have lengths 3 and 2")

In this example, the dimensions of x and y are not compatible, causing a DimensionMismatch error. Make sure that the dimensions of the input arrays are compatible for dot product calculation.

See Also

countfrom, cycle, done, drop, eachindex, enumerate, first, repeated, rest, start, svds, take, vecdot, vecnorm, zip,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field

Checking you are not a robot: