CArray:Dot
The Dot method returns the dot product of this CArray with another CArray.
number = CArray:Dot( CArray ) |
CArray is the other array.
number is the returned dot product.
The dot product is the sum of products of CArray elements at the same indices. For example, consider 2 CArray's with values at indices 1, 2, and 3: A = {3,4,5} and B = {10,20,30}. Then A:Dot(B) = 3*10 + 4*20 + 5*30 = 250. Normally, the dot product is only used when you know that the arrays are packed with numbers. An error message will result if any of the elements used is not a number.
This method computes the dot product of 2 sparse arrays. Only the indices common to both arrays are used to compute the dot product. For any two CArray's, even if they are sparsely populated at different indices, A:Dot(B) = B:Dot(A) is true.
The following script computes the straightforward dot product of two CArray's:
|
-- create a CArray |
|
-- set 3 indices to 1.0 |
|
-- create another CArray |
|
-- set 3 indices to 2.0 |
|
-- Result: AdotB = 6 |
The next example computes the dot product of two CArray's that have different dimensions:
|
-- create a CArray A |
|
-- define A indices 1, 2, 3, 4, 5 |
|
-- create a CArray B |
|
-- define B indices 1, 2, 3 |
|
-- result: AdotB = 14 |
|
-- leaves only B indices 2, 3 |
Printf("AdotB = %lg", A:Dot(B) ) |
-- result: AdotB = 12 |
Mira Pro x64 Script User's Guide, Copyright Ⓒ 2023 Mirametrics,
Inc. All Rights Reserved.