Demo of numas.js is avaible via browser console


Go back

Examples


Simple arithmetic

                            

let a = numas.NDArray.new([1, 2, 3, 4], [2, 2]) let b = numas.factory.ones([2, 2]) let c = a.add(b) console.log(c.collect()) // It's also possible to use broadcasting for array of length one let u = numas.NDArray.new([10], [1]) let z = a.mul(u) console.log(z.collect())


Using views

                            

let long = numas.NDArray.new([1,2,3,4,5,6,7,8,9], [3, 3]) //create view array 'long' pointing to first row, second and third column let view = long.get([0, [1, 3]]) console.log(view.collect()) // View contains [2, 3] console.log(long.collect()) let short = numas.factory.ones([2]) view.addAssign(short) // Add to view without creating new array console.log(view.collect()) // View now contains [3, 4] console.log(long.collect()) // Addition to view is reflected into it's "parent"


Avaible methods


Factory

ones(shape, datatype = 'i32') zeros(shape, datatype = 'i32') zeroes(shape, datatype = 'i32') full(value, shape, datatype = 'i32') logspace(start, stop, base, num) linspace(start, stop, num) arange(start, stop, step)

NDArray

new(data, shape, datatype = 'i32')

Instance of NDArray

• General reshape() shape() collect() get(indices) set(value, indices) free() type() len() baseLen() clone() view() • Arithmetic add(other) addAssign(other) sub(other) subAssign(other) mul(other) mulAssign(other) div(other) divAssign(other) • Relational eq(other) neq(other) lt(other) gt(other) le(other) ge(other) • Trigonometric sin() cos() tan() arcsin() arccos() arctan() degrees() radians() rad2deg() deg2rad() • Hyperbolic sinh() cosh() tanh() arcsinh() arccosh() arctanh() • Misc sqrt() • Logarithm loge() log2() log10() log(base) • Reducers sum() prod() • Rounding round(base) floor(base) ceil(base) trunc(base)