series_dot_product()

Calculates the dot product of two numeric series.

The function series_dot_product() takes two numeric series as input, and calculates their dot product.

Syntax

series_dot_product(series1, series2)

Alternate syntax

series_dot_product(series, numeric)

series_dot_product(numeric, series)

Note

The alternate syntax shows that one of the two function arguments can be a numerical scalar.

This numerical scalar will be broadcasted to a vector whose length equals the length of the corresponding numeric series.

For example, series_dot_product([1, 2, 3], 10) will be treated as series_dot_product([1, 2, 3], [10, 10, 10]).

Learn more about syntax conventions.

Parameters

Name Type Required Description
series1, series2 dynamic ✔️ Input arrays with numeric data, to be element-wise multiplied and then summed into a value of type real.

Returns

Returns a value of type real whose value is the sum over the product of each element of series1 with the corresponding element of series2. In case both series length isn't equal, the longer series will be truncated to the length of the shorter one. Any non-numeric element of the input series will be ignored.

Note

If one or both input arrays are empty, the result will be null.

Optimizing performance

For enhanced performance and reduced storage requirements when using this function, consider using the Vector16 encoding policy for storing floating-point vectors that don't require 64 bits precision, such as ML vector embeddings. The Vector16 profile, which utilizes the Bfloat16 floating-point representation, can significantly optimize the operation and reduce storage size by a factor of 4. For more details on the Vector16 encoding policy, refer to the Encoding Policy Types.

Example

range x from 1 to 3 step 1 
| extend y = x * 2
| extend z = y * 2
| project s1 = pack_array(x,y,z), s2 = pack_array(z, y, x)
| extend s1_dot_product_s2 = series_dot_product(s1, s2)
s1 s2 s1_dot_product_s2
[1,2,4] [4,2,1] 12
[2,4,8] [8,4,2] 48
[3,6,12] [12,6,3] 108
range x from 1 to 3 step 1 
| extend y = x * 2
| extend z = y * 2
| project s1 = pack_array(x,y,z), s2 = x
| extend s1_dot_product_s2 = series_dot_product(s1, s2)
s1 s2 s1_dot_product_s2
[1,2,4] 1 7
[2,4,8] 2 28
[3,6,12] 3 63