Getting started
Creating a vector
Let's create some vectors
import slash.vector.*
val v = Vec.fromTuple(1.0, 2.0, 3.0, 4.0, 5.0)
// v: Vec[5] = Array(1.0, 2.0, 3.0, 4.0, 5.0)
val v2 = Vec[5](1.0, 2.0, 3.0, 4.0, 5.0)
// v2: Vec[5] = Array(1.0, 2.0, 3.0, 4.0, 5.0)
val v_fill = Vec.fill[5](1.0)
// v_fill: Vec[5] = Array(1.0, 1.0, 1.0, 1.0, 1.0)
val v_zeros = Vec.zeros[5]
// v_zeros: Vec[5] = Array(0.0, 0.0, 0.0, 0.0, 0.0)
val v_ones = Vec.ones[5]
// v_ones: Vec[5] = Array(1.0, 2.0, 1.0, 1.0, 1.0)
val v_rand = Vec.random[5]
// v_rand: Vec[5] = Array(
// -0.90940500299429,
// -0.018259700551856217,
// -0.8903616261803968,
// -0.6370083684698433,
// -0.8080267311683952
// )
val v_rand_max_min = Vec.random[5](0.5, 2.0)
// v_rand_max_min: Vec[5] = Array(
// 0.872044385361405,
// 1.7162709830135006,
// 1.9422600502512586,
// 0.6779053973287785,
// 0.8091160248104509
// )
And do some stuff
v + v_fill
// res0: Vec[5] = Array(2.0, 3.0, 4.0, 5.0, 6.0)
v2.dot(v_zeros)
// res1: Double = 0.0
v_rand -= v_ones
// native indexing is fast...
v_ones(1) = 2.0
v_ones(4)
// res4: Double = 1.0
v_ones
// res5: Vec[5] = Array(1.0, 2.0, 1.0, 1.0, 1.0)
v.mean
// res6: Double = 3.0
v.corr(v_rand)
// res7: Double = -0.17749786121279734
v_rand.elementRanks
// res8: Vec[5] = Array(1.0, 5.0, 2.0, 4.0, 3.0)