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
You can add two tensors using tensorA.add(tensorB)
You can add two tensors using tensorA.add(tensorB):
const tensorA = tf.tensor([[1, 2], [3, 4], [5, 6]]);
const tensorB = tf.tensor([[1,-1], [2,-2], [3,-3]]);
// Tensor Addition
const tensorNew = tensorA.add(tensorB);
// Result: [ [2, 1], [5, 2], [8, 3] ]
You can subtract two tensors using tensorA.sub(tensorB):
const tensorA = tf.tensor([[1, 2], [3, 4], [5, 6]]);
const tensorB = tf.tensor([[1,-1], [2,-2], [3,-3]]);
// Tensor Subtraction
const tensorNew = tensorA.sub(tensorB);
// Result: [ [0, 3], [1, 6], [2, 9] ]
You can multiply two tensors using tensorA.mul(tensorB):
const tensorA = tf.tensor([1, 2, 3, 4]);
const tensorB = tf.tensor([4, 4, 2, 2]);
// Tensor Multiplication
const tensorNew = tensorA.mul(tensorB);
// Result: [ 4, 8, 6, 8 ]
You can divide two tensors using tensorA.div(tensorB):
const tensorA = tf.tensor([2, 4, 6, 8]);
const tensorB = tf.tensor([1, 2, 2, 2]);
// Tensor Division
const tensorNew = tensorA.div(tensorB);
// Result: [ 2, 2, 3, 4 ]
You can square a tensor using tensor.square():
const tensorA = tf.tensor([1, 2, 3, 4]);
// Tensor Square
const tensorNew = tensorA.square();
// Result [ 1, 4, 9, 16 ]
The number of elements in a tensor is the product of the sizes in the shape.
Since there can be different shapes with the same size, it is often useful to reshape a tensor to other shapes with the same size.
You can reshape a tensor using tensor.reshape():
const tensorA = tf.tensor([[1, 2], [3, 4]]);
const tensorB = tensorA.reshape([4, 1]);
// Result: [ [1], [2], [3], [4] ]