Open In App

Tensorflow.js tf.linspace() Function

Last Updated : 18 May, 2021
Improve
Improve
Like Article
Like
Save
Share
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 .linspace() function is used to find a regularly distanced series of numbers for a stated interval.

Syntax :  

tf.linspace(start, stop, num)

Parameters:  

  • start: It is the stated start value of the series which is to be generated and is of type number.
  • stop: It is the stated end value of the series which is to be generated and is of type number.
  • num: It is the stated number of values which are to be generated and is of type number.

Return Value: It returns the tf.Tensor1D object.

Example 1:  

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Defining all the parameters
var strt = 3;
var stp = 20;
var num = 5;
  
// Calling linspace() method and
// Printing output
tf.linspace(strt, stp, num).print();


Output:

Tensor
    [3, 7.25, 11.5, 15.75, 20]

Example 2: Using float values for all the stated parameters.

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Calling linspace() method and
// Printing output
tf.linspace(12.4, 29.7, 5.4).print();


Output:

Tensor
    [12.3999996, 16.3318176, 20.2636356, 24.1954536, 28.1272717]

Reference: https://js.tensorflow.org/api/latest/#linspace


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads