Tensorflow.js tf.layers.add() Function Last Updated : 14 Oct, 2022 Comments Improve Suggest changes Like Article Like Report 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. It also helps the developers to develop ML models in JavaScript language and can use ML directly in the browser or Node.js. The tf.layers.add() function is used to calculate addition of every element when multiple arrays are provided as inputs. Syntax: tf.layers.add().apply([input1, input2,input3,......,inputn]) Parameters: inputShape: It is an optional parameter which is used to create the input layer and it take values like number and null.batchInputShape: It is an optional parameter which is used to create the input layer before the main layer and it take values like number and null.batchSize: It is an optional parameter used to make batchInputShape and it accepts only numbers.dtype: It is an optional parameter and it stands for data type. By default it has 'float32' and also supports other values like 'int32', 'bool' etc.name: It is an optional parameter and is used to define the name of the layer and it accepts strings.trainable: It is an optional parameter that determines the provided input layers are updated or not. It accepts boolean values.weights: It possesses the starting weights of the layer. It is also a optional parameter.inputDType: It is an optional parameter used for input data type. Like dtype it also supports all its values. Return Value: It returns Add. Example 1: JavaScript // Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" const input1 = tf.input({shape: [90.5, 3]}); const input2 = tf.input({shape: [90.5, 3]}); const addLayer = tf.layers.add(); const sum = addLayer.apply([input1, input2]); console.log(JSON.stringify(sum.shape)); Output: [null,90.5,3] Example 2: JavaScript // Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" const input1 = tf.input({shape: [127.65, 56]}); const input2 = tf.input({shape: [127.65, 56]}); const input3 = tf.input({shape: [127.65, 56]}); const input4 = tf.input({shape: [127.65, 56]}); const input5 = tf.input({shape: [127.65, 56]}); const input6 = tf.input({shape: [127.65, 56]}); const input7 = tf.input({shape: [127.65, 56]}); const input8 = tf.input({shape: [127.65, 56]}); const addLayer = tf.layers.add(); const sum = addLayer.apply([input1, input2, input3, input4, input5, input6, input7, input8]); console.log(JSON.stringify(sum.shape)); Output: [null,127.65,56] Reference: https://js.tensorflow.org/api/latest/#layers.add Create Quiz Comment B bunnyram19 Follow 0 Improve B bunnyram19 Follow 0 Improve Article Tags : JavaScript Web Technologies Tensorflow.js Tensorflow.js-Merge Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings5 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in JavaScript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)8 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readScope of Variables in JavaScript3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like