Array creation#

Constructor#

Constructor#

import v from 'vectorious';

new v([1, 2, 3, 4]);
// [1, 2, 3, 4]

new v(new Float32Array([1, 2, 3, 4]));

Array#

The shorthand array method:

import { array } from 'vectorious';

array([1, 2, 3, 4]);

// [1, 2, 3, 4]

array(new Int8Array([1, 2, 3, 4]));
// [0, 0, 0, 0] (dtype: 'int8')

Matrix#

Matrix creation

import { matrix } from 'vectorious';

matrix(2, 2);
// [[0, 0], [0, 0]]

Zeros#

Zeros

import { zeros } from 'vectorious';

zeros(4);
// [0, 0, 0, 0]

zeros(2, 2);
// [[0, 0], [0, 0]]

zeros(2, 2, 2);
// [[[0, 0]], [[0, 0]]]

Ones#

Ones

import { ones } from 'vectorious';

ones(4);
// [1, 1, 1, 1]

ones(2, 2);
// [[1, 1], [1, 1]]

ones(2, 2, 2);
// [[[1, 1]], [[1, 1]]]

Random#

Creates a vector containing random samples from a uniform distribution over \([0, 1)\).

import { ones } from 'vectorious';

ones(4);
// [1, 1, 1, 1]

ones(2, 2);
// [[1, 1], [1, 1]]

ones(2, 2, 2);
// [[[1, 1]], [[1, 1]]]

Magic#

Creates a magic matrix (the sums of the numbers in each row, each column, and both main diagonals are the same).

import { magic } from 'vectorious';

magic(3);
// [[2, 7, 6], [9, 5, 1], [4, 3, 8]]