sum

Synopsis

float sum(set)
float sum(tset, int)

Description

In its first form, sum computes the sum of all numbers in a given set, and returns it as a float. Only numbers or strings that can be interpreted as numbers are counted; strings that cannot be parsed as a number are treated as having the value zero.

The second form of is command allows it to be applied to one column of an edge set or a tuple set. In this case, the first parameter specifies the data to work on, and the second parameter specifies the number of the column of interest (the numbering is zero-based).

Example

>> ints = {1,2,3,4}
>> floats={1.5, 2.5, 3.5, 4.5}
>> strings = {"aaa", "bbb", "ccc", "ddd"}
>> sum (ints)
10.0
>> sum (floats)
12.0
>> sum (ints + floats)
22.0
>> sum (ints + floats + strings)
22.0
>> sum (strings)
0.0
>> sum ({})
0.0
>> sum (ints X floats, 0)
40.0
>> sum (ints X floats, 1)
48.0
>>