Property

new StrVector([arg])

Vector - array of strings.

Example

var la = require('qminer').la;
// create a new empty vector
var vec = new la.StrVector();
// create a new vector
var vec2 = new la.StrVector(['a', 'b', 'c']);

Parameter

Name Type Optional Description

arg

(Array of string or module:la.StrVector)

Yes

Constructor arguments. There are two ways of constructing:
1. using an array of vector elements. Example: using ['a', 'b', 'c'] 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.StrVector(['a', 'b', 'c']);
// get the length of the vector
var len = x.length; // returns 3

Methods

at(index) → string

Returns element at index.

Example

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

Parameter

Name Type Optional Description

index

number

 

Element index (zero-based).

Returns

stringB Vector element.

load(fin) → module:la.StrVector

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.StrVector();
// 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.StrVectorB Self. The vector is filled using the input stream fin.

loadascii(fin) → module:la.StrVector

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.StrVector();
// 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.StrVectorB 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.StrVector(['a', 'b', 'c']);
// push an element to the vector
vec.push('xyz');

Parameter

Name Type Optional Description

val

string

 

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.StrVector(['a', 'b', 'c']);
var vec2 = new la.StrVector(['d', 'e']);
// append the two vectors
vec.pushV(vec2);

Parameter

Name Type Optional Description

vec

module:la.StrVector

 

The appended vector.

Returns

numberB The new length property of the vectors.

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

Sets an element in vector.

Example

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

Parameters

Name Type Optional Description

idx

number

 

Index (zero based).

val

string

 

Element value.

Returns

module:la.StrVectorB 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.StrVector(['a', 'b', 'c']);
// 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.StrVector(['a', 'b', 'c']);
// 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.StrVector

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.StrVector(['asd', 'z', 'kkkk']);
// shuffle the elements
vec.shuffle();
Returns

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

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

Changes the vector by removing and adding elements.

Example

var la = require('qminer').la;
// create a new vector
var vec = new la.StrVector(['a', 'b', 'c']);
// splice the vector by removing the last two elements and adding 'd', 'e'
vec.splice(1, 2, 'd', 'e')// returns vector ['a', 'd', 'e']

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.StrVectorB Self. The selected elements are removed/replaced.

subVec(arg) → module:la.StrVector

Returns a subvector.

Example

// import la module
var la = require('qminer').la;
// create a new vector
var vec = new la.StrVector(['a', 'b', 'c']);
// get the subvector of the first two elements
var subvec = vec.subVec([0, 1]);

Parameter

Name Type Optional Description

arg

(Array of number or module:la.IntVector)

 

Index array or vector. Indices can repeat (zero based).

Returns

module:la.StrVectorB Subvector, where the i-th element is the arg[i]-th element of the instance.

toArray() → Array of string

Copies the vector into a JavaScript array of strings.

Example

// import la module
var la = require('qminer').la;
// create a new vector
var vec = new la.StrVector(["one", "two", "three"]);
// create a JavaScript array out of vec
var arr = vec.toArray(); // returns an array ["one", "two", "three"]
Returns

Array of stringB A JavaScript array of strings.

toString() → string

Returns the vector as string.

Example

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

stringB String representation.

trunc(idx) → module:la.StrVector

Deletes elements with sprecific index or more.

Example

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

Parameter

Name Type Optional Description

idx

string

 

Index (zero based).

Returns

module:la.StrVectorB 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.StrVector(['a', 'b', 'c']);
// add two elements to the beggining of the vector
var len = vec.unshift('d', 'e'); // returns 5

Parameter

Name Type Optional Description

args

string

 

One or more elements to be added to the vector.

Value can be repeated.

Returns

numberB The new length of vector.