Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment.
The tf.addN() function is used to add a specified list of Tensors element-wise. Each Tensor should be of the same shape and data type.
Syntax:
tf.addN (tensors)
Parameters: This function accepts a parameter which is illustrated below:
- tensors: The array/list of specified tensors with the same shape and data type.
Return Value: It returns a Tensor of added elements.
Example 1:
Javascript
// Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Initializing some Tensors const a = tf.tensor1d([0, 1, 2]); const b = tf.tensor1d([3, 4, 5]); // Calling the .addN() function over // the above Tensors as its parameters tf.addN([a, b]).print(); |
Output:
Tensor [3, 5, 7]
Example 2:
Javascript
// Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Using some Tensors as the parameter // for the .addN() function tf.addN([[12, 5, 6], [3, 2, 5], [2, 7, 9]]).print(); |
Output:
Tensor [17, 14, 20]
Reference: https://js.tensorflow.org/api/latest/#addN