Tensorflow.js tf.linspace() Function
Last Updated :
18 May, 2021
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
import * as tf from "@tensorflow/tfjs"
var strt = 3;
var stp = 20;
var num = 5;
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
import * as tf from "@tensorflow/tfjs"
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
Share your thoughts in the comments
Please Login to comment...