The important part is to make a new sequence with var c = newSeq[float]()
and add values to it with c.add(value)
, as in the first block here:
var a = @[100.0, 102.0, 101.0, 114.0, 128.0, 130.0, 127.0]
var b = a[1..a.high] & a[a.high]
import math
block: # Iterative with math.mean
var c = newSeq[float]()
for i in a.low..a.high:
c.add(b[i]/a[i])
echo mean(c)
block: # Iterative without math.mean (most efficient)
var myMean = 0.0
for i in a.low..a.high:
myMean += b[i]/a[i]
myMean /= a.len.float
echo myMean
import sequtils
block: # Functionally (not really nim-like)
echo zip(a, b).map(proc(x): float = x.b/x.a).mean