qminer
Version:
A C++ based data analytics platform for processing large-scale real-time streams containing structured and unstructured data
1,235 lines (1,233 loc) • 62.7 kB
HTML
<!doctype html>
<html>
<head>
<meta name="generator" content="JSDoc 3">
<meta charset="utf-8">
<title>Class: Vector</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
<link href="css/baseline.css" rel="stylesheet">
</head>
<body onload="prettyPrint()">
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">QMiner JavaScript API v9.4.0</a>
</div>
</div>
</nav>
<div id="jsdoc-body-container">
<div id="jsdoc-content">
<div id="jsdoc-content-container">
<div id="jsdoc-main" role="main">
<header class="page-header">
<div class="symbol-detail-labels"><span class="label label-kind">class</span> <span class="label label-static">static</span></div>
<h1><small><a href="module-la.html">la</a>.<wbr></small><span class="symbol-name">Vector</span></h1>
<p class="source-link">Source: <a href="ladoc.js.html#source-line-1745">ladoc.<wbr>js:1745</a></p>
<div class="symbol-classdesc">
<p>The number vector representation. Wraps a C++ array.</p>
</div>
<dl class="dl-compact">
</dl>
</header>
<section id="summary">
<div class="summary-callout">
<h2 class="summary-callout-heading">Property</h2>
<div class="summary-content">
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="module-la.Vector.html#length">length</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
</div>
<div class="summary-column">
</div>
</div>
</div>
<div class="summary-callout">
<h2 class="summary-callout-heading">Methods</h2>
<div class="summary-content">
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="module-la.Vector.html#at">at(index)</a></dt>
<dd>
</dd>
<dt><a href="module-la.Vector.html#cosine">cosine(vec)</a></dt>
<dd>
</dd>
<dt><a href="module-la.Vector.html#diag">diag()</a></dt>
<dd>
</dd>
<dt><a href="module-la.Vector.html#getMaxIdx">getMaxIdx()</a></dt>
<dd>
</dd>
<dt><a href="module-la.Vector.html#inner">inner(vec)</a></dt>
<dd>
</dd>
<dt><a href="module-la.Vector.html#load">load(fin)</a></dt>
<dd>
</dd>
<dt><a href="module-la.Vector.html#loadascii">loadascii(fin)</a></dt>
<dd>
</dd>
<dt><a href="module-la.Vector.html#minus">minus(vec)</a></dt>
<dd>
</dd>
<dt><a href="module-la.Vector.html#multiply">multiply(val)</a></dt>
<dd>
</dd>
<dt><a href="module-la.Vector.html#norm">norm()</a></dt>
<dd>
</dd>
<dt><a href="module-la.Vector.html#normalize">normalize()</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="module-la.Vector.html#outer">outer(vec)</a></dt>
<dd>
</dd>
<dt><a href="module-la.Vector.html#plus">plus(vec)</a></dt>
<dd>
</dd>
<dt><a href="module-la.Vector.html#print">print()</a></dt>
<dd>
</dd>
<dt><a href="module-la.Vector.html#push">push(val)</a></dt>
<dd>
</dd>
<dt><a href="module-la.Vector.html#pushV">pushV(vec)</a></dt>
<dd>
</dd>
<dt><a href="module-la.Vector.html#put">put(idx, val)</a></dt>
<dd>
</dd>
<dt><a href="module-la.Vector.html#save">save(fout)</a></dt>
<dd>
</dd>
<dt><a href="module-la.Vector.html#saveascii">saveascii(fout)</a></dt>
<dd>
</dd>
<dt><a href="module-la.Vector.html#shuffle">shuffle()</a></dt>
<dd>
</dd>
<dt><a href="module-la.Vector.html#sort">sort([arg])</a></dt>
<dd>
</dd>
<dt><a href="module-la.Vector.html#sortPerm">sortPerm([asc])</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="module-la.Vector.html#sparse">sparse()</a></dt>
<dd>
</dd>
<dt><a href="module-la.Vector.html#spDiag">spDiag()</a></dt>
<dd>
</dd>
<dt><a href="module-la.Vector.html#splice">splice(start, deleteCount[, .<wbr>.<wbr>.<wbr>itemN])</a></dt>
<dd>
</dd>
<dt><a href="module-la.Vector.html#subVec">subVec(arg)</a></dt>
<dd>
</dd>
<dt><a href="module-la.Vector.html#sum">sum()</a></dt>
<dd>
</dd>
<dt><a href="module-la.Vector.html#toArray">toArray()</a></dt>
<dd>
</dd>
<dt><a href="module-la.Vector.html#toMat">toMat()</a></dt>
<dd>
</dd>
<dt><a href="module-la.Vector.html#toString">toString()</a></dt>
<dd>
</dd>
<dt><a href="module-la.Vector.html#trunc">trunc(idx)</a></dt>
<dd>
</dd>
<dt><a href="module-la.Vector.html#unshift">unshift(.<wbr>.<wbr>.<wbr>args)</a></dt>
<dd>
</dd>
</dl>
</div>
</div>
</div>
</section>
<section>
<h2 id="Vector">new <span class="symbol-name">Vector</span><span class="signature"><span class="signature-params">([arg])</span></span></h2>
<p>Vector - array of doubles.</p>
<section>
<h3>
Example
</h3>
<div>
<pre class="prettyprint"><code>var la = require('qminer').la;
// create a new empty vector
var vec = new la.Vector();
// create a new vector
var vec2 = new la.Vector([1, 2, 3]);</code></pre>
</div>
</section>
<section>
<h3>Parameter</h3>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>arg</p>
</td>
<td>
<p>(Array of number or <a href="module-la.Vector.html">module:la.Vector</a>)</p>
</td>
<td>
<p>Yes</p>
</td>
<td>
<p>Constructor arguments. There are two ways of constructing:
<br>1. using an array of vector elements. Example: using <code>[1, 2, 3]</code> creates a vector of length 3,
<br>2. using a vector (copy constructor).
</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
</dl>
</section>
<section>
<h2>Property</h2>
<section>
<h3 id="length"><span class="symbol-name">length</span></h3>
<p>Gives the length of vector. Type <code>number</code>.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>var la = require('qminer').la;
// create a new vector
var x = new la.Vector([1, 2, 3]);
// get the length of the vector
var len = x.length; // returns 3</code></pre>
</div>
</section>
<dl class="dl-compact">
</dl>
</section>
<h2>Methods</h2>
<section>
<h3 id="at"><span class="symbol-name">at</span><span class="signature"><span class="signature-params">(index)</span> → <span class="signature-returns"> number</span></span></h3>
<p>Returns element at index.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import la module
var la = require('qminer').la;
// create a new vector
var vec = new la.Vector([1, 2, 3]);
// get the element at index 1
var el = vec[1];</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>index</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>Element index (zero-based).</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>number</code>B Vector element.</p>
</dd>
</dl>
<h3 id="cosine"><span class="symbol-name">cosine</span><span class="signature"><span class="signature-params">(vec)</span> → <span class="signature-returns"> number</span></span></h3>
<p>Returns the cosine between the two vectors.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>var la = require('qminer').la;
// create two new vectors
var x = new la.Vector([1, 0]);
var y = new la.Vector([0, 1]);
// calculate the cosine between those two vectors
var num = x.cosine(y); // returns 0</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>vec</p>
</td>
<td>
<p><a href="module-la.Vector.html">module:la.Vector</a></p>
</td>
<td>
<p> </p>
</td>
<td>
<p>Second vector.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>number</code>B The cosine between the two vectors.</p>
</dd>
</dl>
<h3 id="diag"><span class="symbol-name">diag</span><span class="signature"><span class="signature-params">()</span></span></h3>
<p>Creates a dense diagonal matrix out of the vector.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>var la = require('qminer').la;
// create a new vector
var vec = new la.Vector([4, 5, -1]);
// create a dense matrix with the diagonal equal to vec
var mat = vec.diag();</code></pre>
</div>
</section>
<dl class="dl-compact">
</dl>
<h3 id="getMaxIdx"><span class="symbol-name">getMaxIdx</span><span class="signature"><span class="signature-params">()</span> → <span class="signature-returns"> number</span></span></h3>
<p>Gets the index of the maximal element.</p>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>number</code>B Index of the maximal element in the vector.
// import la modules
var la = require('qminer').la;
// create a new vector
var vec = new la.Vector([1, 2, 3]);
// get the index of the maximum value
var idx = vec.getMaxIdx();</p>
</dd>
</dl>
<h3 id="inner"><span class="symbol-name">inner</span><span class="signature"><span class="signature-params">(vec)</span> → <span class="signature-returns"> number</span></span></h3>
<p>Computes the inner product.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>var la = require('qminer').la;
// create two new vectors
var x = new la.Vector([1, 2, 3]);
var y = new la.Vector([4, 5, -1]);
// get the inner product of the two vectors
var prod = x.inner(y); // returns 11</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>vec</p>
</td>
<td>
<p><a href="module-la.Vector.html">module:la.Vector</a></p>
</td>
<td>
<p> </p>
</td>
<td>
<p>Other vector.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>number</code>B Inner product between the instance and the other vector.</p>
</dd>
</dl>
<h3 id="load"><span class="symbol-name">load</span><span class="signature"><span class="signature-params">(fin)</span> → <span class="signature-returns"> <a href="module-la.Vector.html">module:la.Vector</a></span></span></h3>
<p>Loads the vector from input stream (binary deserialization).</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import fs module
var fs = require('qminer').fs;
var la = require('qminer').la;
// create an empty vector
var vec = new la.Vector();
// open a read stream
var fin = fs.openRead('vec.dat');
// load the vector
vec.load(fin);</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>fin</p>
</td>
<td>
<p><a href="module-fs.FIn.html">module:fs.FIn</a></p>
</td>
<td>
<p> </p>
</td>
<td>
<p>Input stream.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-la.Vector.html">module:la.Vector</a></code>B Self. The vector is filled using the input stream <code>fin</code>.</p>
</dd>
</dl>
<h3 id="loadascii"><span class="symbol-name">loadascii</span><span class="signature"><span class="signature-params">(fin)</span> → <span class="signature-returns"> <a href="module-la.Vector.html">module:la.Vector</a></span></span></h3>
<p>Loads the vector from input stream (ascii deserialization).</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import fs module
var fs = require('qminer').fs;
var la = require('qminer').la;
// create an empty vector
var vec = new la.Vector();
// open a read stream
var fin = fs.openRead('vec.dat');
// load the matrix
vec.loadascii(fin);</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>fin</p>
</td>
<td>
<p><a href="module-fs.FIn.html">module:fs.FIn</a></p>
</td>
<td>
<p> </p>
</td>
<td>
<p>Input stream.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-la.Vector.html">module:la.Vector</a></code>B Self. The vector is filled using the input stream <code>fin</code>.</p>
</dd>
</dl>
<h3 id="minus"><span class="symbol-name">minus</span><span class="signature"><span class="signature-params">(vec)</span> → <span class="signature-returns"> <a href="module-la.Vector.html">module:la.Vector</a></span></span></h3>
<p>Vector substraction.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>var la = require('qminer').la;
// create two new vectors
var x = new la.Vector([1, 2, 3]);
var y = new la.Vector([4, 5, -1]);
// substract the vectors
var z = x.minus(y);</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>vec</p>
</td>
<td>
<p><a href="module-la.Vector.html">module:la.Vector</a></p>
</td>
<td>
<p> </p>
</td>
<td>
<p>Second vector.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-la.Vector.html">module:la.Vector</a></code>B The difference of the instance and the other vector.</p>
</dd>
</dl>
<h3 id="multiply"><span class="symbol-name">multiply</span><span class="signature"><span class="signature-params">(val)</span> → <span class="signature-returns"> <a href="module-la.Vector.html">module:la.Vector</a></span></span></h3>
<p>Multiplies the vector with a scalar.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>var la = require('qminer').la;
// create a new vector
var x = new la.Vector([4, 5, -1]);
// multiply the vector with the scalar 3
var y = x.multiply(3);</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>val</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>Scalar.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-la.Vector.html">module:la.Vector</a></code>B Product of the vector and scalar.</p>
</dd>
</dl>
<h3 id="norm"><span class="symbol-name">norm</span><span class="signature"><span class="signature-params">()</span> → <span class="signature-returns"> number</span></span></h3>
<p>Calculates the norm of the vector.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>var la = require('qminer').la;
// create a new vector
var vec = new la.Vector([4, 5, -1]);
// get the norm of the vector
var norm = vec.norm();</code></pre>
</div>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>number</code>B The norm of the vector.</p>
</dd>
</dl>
<h3 id="normalize"><span class="symbol-name">normalize</span><span class="signature"><span class="signature-params">()</span> → <span class="signature-returns"> <a href="module-la.Vector.html">module:la.Vector</a></span></span></h3>
<p>Normalizes vector.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>var la = require('qminer').la;
// create a new vector
var x = new la.Vector([4, 5, -1]);
// normalize the vector
x.normalize();</code></pre>
</div>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-la.Vector.html">module:la.Vector</a></code>B Self. The vector is normalized.</p>
</dd>
</dl>
<h3 id="outer"><span class="symbol-name">outer</span><span class="signature"><span class="signature-params">(vec)</span> → <span class="signature-returns"> <a href="module-la.Matrix.html">module:la.Matrix</a></span></span></h3>
<p>Creates a dense matrix A by multiplying two vectors x and y: <code>A = x * y^T</code>.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>var la = require('qminer').la;
// create two new vectors
var x = new la.Vector([1, 2, 3]);
var y = new la.Vector([4, 5]);
// create the outer product of these vectors
var A = x.outer(y); // creates the dense matrix [[4, 5], [8, 10], [12, 15]]</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>vec</p>
</td>
<td>
<p><a href="module-la.Vector.html">module:la.Vector</a></p>
</td>
<td>
<p> </p>
</td>
<td>
<p>Second vector.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-la.Matrix.html">module:la.Matrix</a></code>B Matrix obtained by the outer product of the instance and second vector.</p>
</dd>
</dl>
<h3 id="plus"><span class="symbol-name">plus</span><span class="signature"><span class="signature-params">(vec)</span> → <span class="signature-returns"> <a href="module-la.Vector.html">module:la.Vector</a></span></span></h3>
<p>Vector addition.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>var la = require('qminer').la;
// create two new vectors
var x = new la.Vector([1, 2, 3]);
var y = new la.Vector([4, 5, -1]);
// sum the vectors
var z = x.plus(y);</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>vec</p>
</td>
<td>
<p><a href="module-la.Vector.html">module:la.Vector</a></p>
</td>
<td>
<p> </p>
</td>
<td>
<p>Second vector.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-la.Vector.html">module:la.Vector</a></code>B Sum of the instance and the second vector.</p>
</dd>
</dl>
<h3 id="print"><span class="symbol-name">print</span><span class="signature"><span class="signature-params">()</span></span></h3>
<p>Prints the vector on-screen.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import la module
var la = require('qminer').la;
// create a new vector
var vec = new la.Vector([1, 2, 3]);
// print the vector
// For this example it prints:
// [1, 2, 3]
vec.print();</code></pre>
</div>
</section>
<dl class="dl-compact">
</dl>
<h3 id="push"><span class="symbol-name">push</span><span class="signature"><span class="signature-params">(val)</span> → <span class="signature-returns"> number</span></span></h3>
<p>Adds an element to the end of the vector.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import la module
var la = require('qminer').la;
// create a new vector
var vec = new la.Vector([1, 2, 3]);
// push an element to the vector
vec.push(10);</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>val</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The element added to the vector.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>number</code>B The new length property of the object upon which the method was called.</p>
</dd>
</dl>
<h3 id="pushV"><span class="symbol-name">pushV</span><span class="signature"><span class="signature-params">(vec)</span> → <span class="signature-returns"> number</span></span></h3>
<p>Appends a second vector to the first one.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import la module
var la = require('qminer').la;
// create two new vectors
var vec = new la.Vector([1, 2, 3]);
var vec2 = new la.Vector([4, 5]);
// append the two vectors
vec.pushV(vec2);</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>vec</p>
</td>
<td>
<p><a href="module-la.Vector.html">module:la.Vector</a></p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The appended vector.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>number</code>B The new length property of the vectors.</p>
</dd>
</dl>
<h3 id="put"><span class="symbol-name">put</span><span class="signature"><span class="signature-params">(idx, val)</span> → <span class="signature-returns"> <a href="module-la.Vector.html">module:la.Vector</a></span></span></h3>
<p>Sets an element in vector.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import la module
var la = require('qminer').la;
// create a new vector
var vec = new la.Vector([1, 2, 3]);
// set the first element to 10
vec.put(0, 10);</code></pre>
</div>
</section>
<section>
<h4>Parameters</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>idx</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>Index (zero based).</p>
</td>
</tr>
<tr>
<td>
<p>val</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>Element value.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-la.Vector.html">module:la.Vector</a></code>B Self. The values at index <code>idx</code> has been changed to <code>val</code>.</p>
</dd>
</dl>
<h3 id="save"><span class="symbol-name">save</span><span class="signature"><span class="signature-params">(fout)</span> → <span class="signature-returns"> <a href="module-fs.FOut.html">module:fs.FOut</a></span></span></h3>
<p>Saves the vector as output stream (binary serialization).</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import fs module
var fs = require('qminer').fs;
var la = require('qminer').la;
// create a new vector
var vec = new la.Vector([1, 2, 3]);
// open write stream
var fout = fs.openWrite('vec.dat');
// save vector and close write stream
vec.save(fout).close();</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>fout</p>
</td>
<td>
<p><a href="module-fs.FOut.html">module:fs.FOut</a></p>
</td>
<td>
<p> </p>
</td>
<td>
<p>Output stream.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-fs.FOut.html">module:fs.FOut</a></code>B The output stream <code>fout</code>.</p>
</dd>
</dl>
<h3 id="saveascii"><span class="symbol-name">saveascii</span><span class="signature"><span class="signature-params">(fout)</span> → <span class="signature-returns"> <a href="module-fs.FOut.html">module:fs.FOut</a></span></span></h3>
<p>Saves the vector as output stream (ascii serialization).</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import fs module
var fs = require('qminer').fs;
var la = require('qminer').la;
// create a new vector
var vec = new la.Vector([1, 2, 3]);
// open write stream
var fout = fs.openWrite('vec.dat');
// save matrix and close write stream
vec.saveascii(fout).close();</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>fout</p>
</td>
<td>
<p><a href="module-fs.FOut.html">module:fs.FOut</a></p>
</td>
<td>
<p> </p>
</td>
<td>
<p>Output stream.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-fs.FOut.html">module:fs.FOut</a></code>B The output stream <code>fout</code>.</p>
</dd>
</dl>
<h3 id="shuffle"><span class="symbol-name">shuffle</span><span class="signature"><span class="signature-params">()</span> → <span class="signature-returns"> <a href="module-la.Vector.html">module:la.Vector</a></span></span></h3>
<p>Randomly reorders the elements of the vector (inplace).</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import la module
var la = require('qminer').la;
// create a new vector
var vec = new la.Vector([-2.0, 1.0, 3.0]);
// shuffle the elements
vec.shuffle();</code></pre>
</div>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-la.Vector.html">module:la.Vector</a></code>B Self. The elements are randomly reordered.</p>
</dd>
</dl>
<h3 id="sort"><span class="symbol-name">sort</span><span class="signature"><span class="signature-params">([arg])</span> → <span class="signature-returns"> <a href="module-la.Vector.html">module:la.Vector</a></span></span></h3>
<p>Sorts the vector (in place operation).</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>var la = require('qminer').la;
// create a new vector
var vec = new la.Vector([-2.0, 1.0, 3.0]);
// sort ascending
vec.sort(); // sorts to: [-2.0, 1.0, 3.0]
// sort using callback
vec.sort(function(arg1, arg2) { return Math.abs(arg1) - Math.abs(arg2); }); // sorts to: [1.0, -2.0, 3.0]</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>arg</p>
</td>
<td>
<p>(<a href="module-la.html#~vectorCompareCb">module:la~vectorCompareCb</a> or boolean)</p>
</td>
<td>
<p>Yes</p>
</td>
<td>
<p>Sort callback or a boolean ascend flag. Default is boolean and true.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-la.Vector.html">module:la.Vector</a></code>B Self.
<br>1. Vector sorted in ascending order, if <code>arg</code> is boolean and true.
<br>2. Vector sorted in descending order, if <code>arg</code> is boolean and false.
<br>3. Vector sorted by using the comparator callback, if <code>arg</code> is a <a href="module-la.html#~vectorCompareCb">module:la~vectorCompareCb</a>.
</p>
</dd>
</dl>
<h3 id="sortPerm"><span class="symbol-name">sortPerm</span><span class="signature"><span class="signature-params">([asc])</span> → <span class="signature-returns"> Object</span></span></h3>
<p>Sorts the vector and returns the sorted vector as well as the permutation.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import la module
var la = require('qminer').la;
// create a new vector
var vec = new la.Vector([-2.0, 1.0, 3.0]);
// sort ascending
var result = vec.sortPerm();
result.vec; // [-2.0, 1.0, 3.0]
result.perm; // permutation index vector</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>asc</p>
</td>
<td>
<p>boolean</p>
</td>
<td>
<p>Yes</p>
</td>
<td>
<p>Sort in ascending order flag.</p>
<p>Defaults to <code>true</code>.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Object</code>B The object <code>VectorSortResult</code> containing the properties:
<br> <code>VectorSortResult.vec</code> - The sorted vector,
<br> <code>VectorSortResult.perm</code> - Permutation vector, where <code>VectorSortResult.vec[i] = instanceVector[VectorSortResult.perm[i]]</code>.
</p>
</dd>
</dl>
<h3 id="sparse"><span class="symbol-name">sparse</span><span class="signature"><span class="signature-params">()</span> → <span class="signature-returns"> <a href="module-la.SparseVector.html">module:la.SparseVector</a></span></span></h3>
<p>Creates the sparse vector representation of the vector.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>var la = require('qminer').la;
// create a new vector
var vec = new la.Vector([4, 5, -1]);
// create the sparse representation of the vector
var spVec = vec.sparse();</code></pre>
</div>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-la.SparseVector.html">module:la.SparseVector</a></code>B The sparse vector representation.</p>
</dd>
</dl>
<h3 id="spDiag"><span class="symbol-name">spDiag</span><span class="signature"><span class="signature-params">()</span> → <span class="signature-returns"> <a href="module-la.SparseMatrix.html">module:la.SparseMatrix</a></span></span></h3>
<p>Creates a sparse diagonal matrix out of the vector.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>var la = require('qminer').la;
// create a new vector
var vec = new la.Vector([4, 5, -1]);
// create a sparse matrix with the diagonal equal to vec
var mat = vec.spDiag();</code></pre>
</div>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-la.SparseMatrix.html">module:la.SparseMatrix</a></code>B Diagonal matrix, where the (i, i)-th element is the i-th element of vector.</p>
</dd>
</dl>
<h3 id="splice"><span class="symbol-name">splice</span><span class="signature"><span class="signature-params">(start, deleteCount[, ...itemN])</span> → <span class="signature-returns"> <a href="module-la.Vector.html">module:la.Vector</a></span></span></h3>
<p>Changes the vector by removing and adding elements.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>var la = require('qminer').la;
// create a new vector
var vec = new la.Ve