Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Tensorflow.js tf.log() Function

  • Last Updated : 12 May, 2021

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 .log() function is used to find the natural logarithm of the stated tensor input i.e. ln(x) and is done element wise.

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!



Parameters: This function accepts three parameters which are illustrated below:

  • x: It is the tensor input, and it can be of type tf.Tensor, or TypedArray, or Array.

Return Value: It returns the tf.Tensor object.

Example 1:  


// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Defining tensor input elements
const y = tf.tensor1d([1, 15, 38, Math.E]);
// Calling log() method and
// printing output


    [0, 2.7080503, 3.6375861, 0.9999999]

Example 2: In this example, the parameter is passed directly to the log function.


// Importing the tensorflow.js library 
import * as tf from "@tensorflow/tfjs"
// Defining float values
var val = [0.5, 1.5, .66];
// Calling tensor1d method
const y = tf.tensor1d(val);
// Calling log() method
var res = tf.log(y)
// Printing output


    [-0.6931472, 0.4054651, -0.4155154]
My Personal Notes arrow_drop_up
Recommended Articles
Page :