HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
A Tensor is a N-dimensional Matrix
The number of directions a tensor can have in a N-dimensional space, is called the Rank of the tensor.
The rank is denoted R.
A Scalar is a single number.
A Vector is an array of numbers.
A Matrix is a 2-dimensional array.
Technically, all of the above are tensors, but when we speak of tensors, we generally speak of matrices with a dimension larger than 2 (R > 2).
In linear algebra, the most simple math object is the Scalar:
const scalar = 1;
Another simple math object is the Array:
const array = [ 1, 2, 3 ];
Matrices are 2-dimensional Arrays:
const matrix = [ [1,2],[3,4],[5,6] ];
Vectors can be written as Matrices with only one column:
const vector = [ [1],[2],[3] ];
Vectors can also be written as Arrays:
const vector = [ 1, 2, 3 ];
Tensors are N-dimensional Arrays:
const tensor = [ [1,2,3],[4,5,6],[7,8,9] ];
Programming tensor operations in JavaScript, can easily become a spaghetti of loops.
Using a JavaScript library will save you a lot of headache.
One of the most common libraries to use for tensor operations is called tensorflow.js.
const tensorA = tf.tensor([[1, 2], [3, 4], [5, 6]]);
const tensorB = tf.tensor([[1,-1], [2,-2], [3,-3]]);
// Tensor Addition
const tensorAdd = tensorA.add(tensorB);
// Result [ [2, 1], [5, 2], [8, 3] ]
const tensorA = tf.tensor([[1, 2], [3, 4], [5, 6]]);
const tensorB = tf.tensor([[1,-1], [2,-2], [3,-3]]);
// Tensor Subtraction
const tensorSub = tensorA.sub(tensorB);
// Result [ [0, 3], [1, 6], [2, 9] ]