Sunday, November 17, 2024
Google search engine
HomeLanguagesJavascriptTensorflow.js tf.addN() Function

Tensorflow.js tf.addN() Function

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments