Tensorflow.js tf.stack() Function Last Updated : 10 May, 2021 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 helps developers to develop ML models in JavaScript, and use ML directly in the browser or in Node.js. The tf.stack() function is used to create a stack of tf,tensors into an r+1 rank tf.tensor. Syntax: tf.stack(tensors, axis) Parameters: This function accepts two parameters as mentioned above and discussed below. tensors: list of tensor objects to be used, with the same shape and dtype.axis: It is an axis of the stack along. Return Value: It returns tf.Tensor. Example 1: JavaScript // Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Making a tensor a const a = tf.tensor1d([99, 999, 999]); // Making a tensor b const b = tf.tensor1d([322, 411, 888]); // Making a tensor c const c = tf.tensor1d([523, 622, 666]); // Printing the stack tf.stack([a, b, c]).print(); Output: Tensor [[99 , 999, 999], [322, 411, 888], [523, 622, 666]] Example 2: In this example, making the stack with axis as the 2nd parameter. JavaScript // Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Making a tensor a const a = tf.tensor1d([99, 999, 999]); // Making a tensor b const b = tf.tensor1d([322, 411, 888]); // Making a tensor c const c = tf.tensor1d([523, 622, 666]); // Printing the stack tf.stack([a, b, c], 1).print(); Output: Tensor [[99 , 322, 523], [999, 411, 622], [999, 888, 666]] Reference: https://js.tensorflow.org/api/latest/#stack Comment More infoAdvertise with us Next Article Tensorflow.js tf.stack() Function taran910 Follow Improve Article Tags : JavaScript Web Technologies Tensorflow.js Similar Reads Tensorflow.js tf.tan() Function Tensorflow.js is an open-source library that is being developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The .tan() function is used to find the tangent of the stated tensor input and is done element wise. Syntax: tf.t 2 min read Tensorflow.js tf.step() 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.step() function is used to return the step of the input tensor's elements i.e. it returns 1 if the element is greater than 0 el 1 min read Tensorflow.js tf.pad() 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. It also helps the developers to develop ML models in JavaScript language and can use ML directly in the browser or in Node.js. The tf. 2 min read Tensorflow.js tf.sum() 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.sum() function is used to calculate sum of the elements of a specified Tensor across its dimension. It reduces the given input 2 min read Tensorflow.js tf.max() 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.max() function is used to calculate the maximum value from the specified Tensor across its dimension. It reduces the given inpu 2 min read Tensorflow.js tf.scalar() 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 .scalar() function is used to create a scalar type of tensor means. A scalar is a zero-dimension array and is also called a rank-0 2 min read Tensorflow.js tf.ones() Function Tensorflow.js is an open-source library for running machine learning models and deep learning neural networks in the browser or node environment. The tf.ones() function is used to create a new tensor where all elements are set to 1. Syntax: tf.ones(shape, dtype, name) Parameters: shape: It takes the 2 min read Tensorflow.js tf.reshape() 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. 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.res 2 min read Tensorflow.js tf.print() 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. It helps developers to develop ML models in JavaScript, and use ML directly in the browser or in Node.js. The tf.print() function is u 2 min read Tensorflow.js tf.range() 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. range() is used to create a new tf.Tensor1D filled with the numbers in the range provided with the help of start, stop, step, 2 min read Like