CMatrixRow:Dot
The Dot method returns the dot product of this CMatrixRow with another CMatrixRow.
number = CMatrixRow:Dot( CMatrixRow ) where |
CMatrixRow is abother CMatrixRow object.
number is the returned dot product.
The dot product is the sum of products of CMatrixRow elements at the same indices. For example, consider 2 CMatrixRow'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 used with arrays containing only 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 CMatrixRow'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 CMatrixRow's:
|
-- create a CMatrixRow |
|
-- set 3 indices to 1.0 |
|
-- create another CMatrixRow |
|
-- set 3 indices to 2.0 |
|
-- Result: AdotB = 6 |
The next example computes the dot product of two CMatrixRow's that have different dimensions:
|
-- create a CMatrixRow A |
|
-- define A indices 1, 2, 3, 4, 5 |
|
-- create a CMatrixRow B |
|
-- define B indices 1, 2, 3 |
|
-- result: AdotB = 14 |
|
-- leaves only B indices 2, 3 |
|
-- result: AdotB = 12 |