TSum
The TSum function returns the sum of values in a data collection. The collection can be a Lua table or an object of type CImage, CArray, or CMatrix. To process a variable list of values and tables, use the slower VSum function.
nSum = TSum( table )
nSum = TSum( CImage )
nSum = TSum( CArray )
nSum = TSum( CMatrix )
where
table, CImage, CArray, or CMatrix contains the target data.
nSum is the sum of the data.
All data except for the CImage class use double precision real numbers having data type "double". The CImage class supports values ranging from byte to double plus other data types. Numeric values other than double can be processed by first converting the table to a CImage.
The CStats:Mean method also can be used to calculate the sum by then multiplying by the number of values used, in he sense Sum = (Mean * Number). The CStats class version also adds the ability to constrain the point sample to a rectangular region of a CImage or CMatrix.
The following script returns the sumof values in a table of 1 million random numbers.
|
-- create a table of numbers |
|
-- find the sum |
|
-- list the result |