Property

new BoolVector([arg])

Vector - array of boolean.

Example

var la = require('qminer').la;
// create a new empty vector
var vec = new la.BoolVector();
// create a new vector
var vec2 = new la.BoolVector([true, true, false]);

Parameter

Name Type Optional Description

arg

(Array of boolean or module:la.BoolVector)

Yes

Constructor arguments. There are two ways of constructing:
1. using an array of vector elements. Example: using [true, true, false] creates a vector of length 3,
2. using a vector (copy constructor).

Property

length

Gives the length of vector. Type number.

Example

var la = require('qminer').la;
// create a new vector
var x = new la.BoolVector([true, true, false]);
// get the length of the vector
var len = x.length; // returns 3

Methods

at(index) → boolean

Returns element at index.

Example

// import la module
var la = require('qminer').la;
// create a new vector
var vec = new la.BoolVector([true, true, false]);
// get the element at index 1
var el = vec[1];

Parameter

Name Type Optional Description

index

number

 

Element index (zero-based).

Returns

booleanB Vector element.

load(fin) → module:la.BoolVector

Loads the vector from input stream (binary deserialization).

Example

// import fs module
var fs = require('qminer').fs;
var la = require('qminer').la;
// create an empty vector
var vec = new la.BoolVector();
// open a read stream
var fin = fs.openRead('vec.dat');
// load the vector
vec.load(fin);

Parameter

Name Type Optional Description

fin

module:fs.FIn

 

Input stream.

Returns

module:la.BoolVectorB Self. The vector is filled using the input stream fin.

loadascii(fin) → module:la.BoolVector

Loads the vector from input stream (ascii deserialization).

Example

// import fs module
var fs = require('qminer').fs;
var la = require('qminer').la;
// create an empty vector
var vec = new la.BoolVector();
// open a read stream
var fin = fs.openRead('vec.dat');
// load the matrix
vec.loadascii(fin);

Parameter

Name Type Optional Description

fin

module:fs.FIn

 

Input stream.

Returns

module:la.BoolVectorB Self. The vector is filled using the input stream fin.

push(val) → number

Adds an element to the end of the vector.

Example

// import la module
var la = require('qminer').la;
// create a new vector
var vec = new la.BoolVector([true, true, false]);
// push an element to the vector
vec.push(false);

Parameter

Name Type Optional Description

val

boolean

 

The element added to the vector.

Returns

numberB The new length property of the object upon which the method was called.

pushV(vec) → number

Appends a second vector to the first one.

Example

// import la module
var la = require('qminer').la;
// create two new vectors
var vec = new la.BoolVector([true, true, false]);
var vec2 = new la.BoolVector([false, true]);
// append the two vectors
vec.pushV(vec2);

Parameter

Name Type Optional Description

vec

module:la.BoolVector

 

The appended vector.

Returns

numberB The new length property of the vectors.

put(idx, val) → module:la.BoolVector

Sets an element in vector.

Example

// import la module
var la = require('qminer').la;
// create a new vector
var vec = new la.BoolVector([true, true, false]);
// set the first element to false
vec.put(0, false);

Parameters

Name Type Optional Description

idx

number

 

Index (zero based).

val

boolean

 

Element value.

Returns

module:la.BoolVectorB Self. The values at index idx has been changed to val.

save(fout) → module:fs.FOut

Saves the vector as output stream (binary serialization).

Example

// import fs module
var fs = require('qminer').fs;
var la = require('qminer').la;
// create a new vector
var vec = new la.BoolVector([true, true, false]);
// open write stream
var fout = fs.openWrite('vec.dat');
// save vector and close write stream
vec.save(fout).close();

Parameter

Name Type Optional Description

fout

module:fs.FOut

 

Output stream.

Returns

module:fs.FOutB The output stream fout.

saveascii(fout) → module:fs.FOut

Saves the vector as output stream (ascii serialization).

Example

// import fs module
var fs = require('qminer').fs;
var la = require('qminer').la;
// create a new vector
var vec = new la.BoolVector([true, true, false]);
// open write stream
var fout = fs.openWrite('vec.dat');
// save matrix and close write stream
vec.saveascii(fout).close();

Parameter

Name Type Optional Description

fout

module:fs.FOut

 

Output stream.

Returns

module:fs.FOutB The output stream fout.

shuffle() → module:la.BoolVector

Randomly reorders the elements of the vector (inplace).

Example

// import la module
var la = require('qminer').la;
// create a new vector
var vec = new la.BoolVector([true, false, false]);
// shuffle the elements
vec.shuffle();
Returns

module:la.BoolVectorB Self. The elements are randomly reordered.

splice(start, deleteCount[, ...itemN]) → module:la.BoolVector

Changes the vector by removing and adding elements.

Example

var la = require('qminer').la;
// create a new vector
var vec = new la.BoolVector([true, true, false]);
// splice the vector by removing the last two elements and adding false, true
vec.splice(1, 2, false, true)// returns vector [true, false, true]

Parameters

Name Type Optional Description

start

number

 

Index at which to start changing the array.

deleteCount

number

 

Number of elements to be removed.

itemN

number

Yes

The element(s) to be add to the array. If no elements are given, splice() will only remove elements from the array.

Value can be repeated.

Returns

module:la.BoolVectorB Self. The selected elements are removed/replaced.

toArray() → Array of boolean

Copies the vector into a JavaScript array of booleans.

Example

// import la module
var la = require('qminer').la;
// create a new vector
var vec = new la.BoolVector([true, false, true]);
// create a JavaScript array out of vec
var arr = vec.toArray(); // returns an array [true, false, true]
Returns

Array of booleanB A JavaScript array of booleans.

toString() → string

Returns the vector as string.

Example

var la = require('qminer').la;
// create a new vector
var vec = new la.BoolVector([true, true, false]);
// create vector as string
vec.toString(); // returns 'true, true, false'
Returns

stringB String representation.

trunc(idx) → module:la.BoolVector

Deletes elements with sprecific index or more.

Example

var la = require('qminer').la;
// create a new vector
var vec = new la.BoolVector([true, true, false]);
// trunc all elements with index 1 or more
vec.trunc(1); // returns vector [true]

Parameter

Name Type Optional Description

idx

boolean

 

Index (zero based).

Returns

module:la.BoolVectorB Self after truncating.

unshift(...args) → number

Adds elements to the beginning of the vector.

Example

// import la module
var la = require('qminer').la;
// create a new vector
var vec = new la.BoolVector([true, true, false]);
// add two elements to the beggining of the vector
var len = vec.unshift(false, true); // returns 5

Parameter

Name Type Optional Description

args

boolean

 

One or more elements to be added to the vector.

Value can be repeated.

Returns

numberB The new length of vector.