Tensorflow.js tf.ones() Function Last Updated : 18 May, 2021 Comments Improve Suggest changes Like Article Like Report 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 shape of the tensor. It can be a multi-dimensional array or an int32dtype: It takes the data type of the 1 we are inserting. It is by default set to float32, however, it can be int32 as well. It is an optional parameter.name: It takes the name of the operation we are performing. It is None by default. It is an optional parameter. Return Value: It returns a tensor with the same data type. Example 1: In this example, we will create a 2D Tensor with all values set to 1 of integer data type. JavaScript // Import tensorflow import tensorflow as tf // Get a Tensor val = tf.ones([10, 10], tf.int32) // Print the Tensor print(val) Output: tf.Tensor( [[1 1 1 1 1 1 1 1 1 1] [1 1 1 1 1 1 1 1 1 1] [1 1 1 1 1 1 1 1 1 1] [1 1 1 1 1 1 1 1 1 1] [1 1 1 1 1 1 1 1 1 1] [1 1 1 1 1 1 1 1 1 1] [1 1 1 1 1 1 1 1 1 1] [1 1 1 1 1 1 1 1 1 1] [1 1 1 1 1 1 1 1 1 1] [1 1 1 1 1 1 1 1 1 1]], shape=(10, 10), dtype=int32) Example 2: In this example, we will create a 1D Tensor with all values set to 1 of float data type. JavaScript // Import tensorflow import tensorflow as tf // Get a Tensor val = tf.ones(5, tf.float32) // Print a Tensor print(val) Output: tf.Tensor([1. 1. 1. 1. 1.], shape=(5,), dtype=float32) Reference:https://js.tensorflow.org/api/latest/#ones Comment More infoAdvertise with us Next Article Tensorflow.js tf.range() Function P pratikraut0000 Follow Improve Article Tags : JavaScript Web Technologies Tensorflow.js Similar Reads Tensorflow.js tf.neg() Function Tensorflow.js is an open-source library which is being developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The .neg() function is used to calculate -1 * x i.e. input tensor and is done element wise. Syntax: Â tf.neg(x) 1 min read Tensorflow.js tf.onesLike() 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.onesLike() function is used to create a tf.Tensor with all elements set to 1 with the same shape as the given tensor. Syntax: t 1 min read Tensorflow.js tf.oneHot() 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.oneHot() function is used to create a one-hot tf.Tensor. The locations represented by indices take the value as 1 (default valu 2 min read Tensorflow.js tf.less() 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.less() function is used to return the tensor of Boolean values for the two specified tensor values i.e. it returns true if the 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.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 Like