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.

Syntax

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.

Example

The following script returns the sumof values in a table of 1 million random numbers.

t = TRand( 1000000 )

-- create a table of numbers

v = TSum( t )

-- find the sum

Printf("Sum = %lg\n", v )

-- list the result

Related Topics

Table Functions

TMean

VSum