Unlike np.dot(), which behaves differently depending on the input arrays' dimensionality, np.vdot() always flattens both inputs into plain 1D vectors first, regardless of their original shape, then computes a single scalar dot product — so it always produces the same kind of result no matter what shape you feed it, even multi-dimensional arrays. For complex-valued arrays, it also takes the complex conjugate of the first argument before multiplying, which is the mathematically standard definition of an inner product for complex vector spaces, and differs from np.dot()'s behavior on complex arrays, which does not conjugate.
1Understanding np.vdot()
Unlike np.dot(), which behaves differently depending on the input arrays' dimensionality, np.vdot() always flattens both inputs into plain 1D vectors first, regardless of their original shape, then computes a single scalar dot product — so it always produces the same kind of result no matter what shape you feed it, even multi-dimensional arrays. For complex-valued arrays, it also takes the complex conjugate of the first argument before multiplying, which is the mathematically standard definition of an inner product for complex vector spaces, and differs from np.dot()'s behavior on complex arrays, which does not conjugate.
Use np.vdot() specifically when working with complex-valued vectors and you need the mathematically correct complex inner product, since np.dot() doesn't conjugate and can give a different, mathematically incorrect result for complex inputs.
import numpy as np
a = np.array([[1, 2], [3, 4]])
b = np.array([[5, 6], [7, 8]])
print(np.vdot(a, b))2Practical Example
Here is a real-world application of np.vdot() showing how it is used in production NumPy code.
import numpy as np
a = np.array([1 + 2j, 3 + 4j])
b = np.array([5 + 6j, 7 + 8j])
print(np.vdot(a, b))
print(np.dot(a, b))3Best Practices
Follow these guidelines when working with np.vdot():
1. Use np.vdot() over np.dot() specifically for complex-valued vectors, where the conjugation matters for a mathematically correct inner product
2. Use vdot() when you want guaranteed flattening behavior regardless of input shape, rather than dot()'s shape-dependent rules
3. Prefer np.dot() for real-valued vectors where the shapes are already 1D, since the two functions behave identically in that specific case
Tip: Use np.vdot() specifically when working with complex-valued vectors and you need the mathematically correct complex inner product, since np.dot() doesn't conjugate and can give a different, mathematically incorrect result for complex inputs.
import numpy as np
a = np.array([[1, 2], [3, 4]])
b = np.array([[5, 6], [7, 8]])
print(np.vdot(a, b))