Tensorflow.js tf.mirrorPad() Function Last Updated : 21 Jun, 2021 Comments Improve Suggest changes Like Article Like Report Tensorflow.js is an open-source library that is developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The .mirrorPad() function is used to pad the stated tensor input with the help of mirror padding. Moreover, this method is beneficial in implementing the REFLECT as well as SYMMETRIC modes of pad. Syntax : tf.mirrorPad(x, paddings, mode) Parameters: x: It is the stated tensor which is to be padded, and it can be of type tf.Tensor, TypedArray, or Array.paddings: It is an array whose length is R, that is the order of the stated tensor. Where, all the elements form a tuple of length two i.e. ints [padBefore, padAfter] that specifies to what extent it is to be padded with every size of the stated tensor. Moreover, in the reflect mode of padding, the padded sections should exclude the extremities, whereas in the symmetric mode of padding the padded sections should not exclude the extremities. And it is of type array.mode: It specifies the mode of padding i.e. either reflect or symmetric. And it is of type string. Note: Firstly, if the stated tensor input is [4, 5, 6] and paddings is [0, 1], then the output will be [4, 5, 6, 5] in the reflect mode of padding and [4, 5, 6, 6] in the symmetric mode of padding.Secondly, if the mode of padding is reflect then the paddings[D, 0] as well as paddings[D, 1] must not be higher than x.shape[D] - 1, whereas if the mode of padding is symmetric then the paddings[D, 0] as well as paddings[D, 1] must not be higher than x.shape[D]. Return Value: It returns tf.Tensor object. Example 1: JavaScript // Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Defining tensor input const y = tf.tensor1d([4, 5, 6]); // Defining paddings and mode of // padding const padding = [[0, 1]]; const mode = 'reflect'; // Calling tf.mirrorPad() method var res = tf.mirrorPad(y, padding, mode); // Printing output res.print(); Output: Tensor [4, 5, 6, 5] Example 2: JavaScript // Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Calling tf.mirrorPad() method and // Printing output tf.mirrorPad(tf.tensor( [2.4, 6.8, 9.3, 5.3]), [[0, 2]], 'symmetric').print(); Output: Tensor [2.4000001, 6.8000002, 9.3000002, 5.3000002, 5.3000002, 9.3000002] Reference: https://js.tensorflow.org/api/latest/#mirrorPad Comment More infoAdvertise with us Next Article Tensorflow.js tf.mirrorPad() Function nidhi1352singh Follow Improve Article Tags : JavaScript Web Technologies Tensorflow.js TensorFlow.js-Transformations Similar Reads 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.prod() 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.prod() function is used to calculate product of the elements of a specified Tensor across its dimension. It reduces the given i 2 min read Tensorflow.js tf.min() 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.min() function is used to calculate the minimum value from the specified Tensor across its dimension. It reduces the given inpu 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 Tensorflow.js tf.reciprocal() 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.reciprocal() function is used to return the reciprocal of the specified tensor's elements. Syntax: tf.reciprocal(x) Parameters: 1 min read Like