Tensorflow.js tf.scalar() Function - GeeksforGeeks

13 May, 2021Tensorflow.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 .scalar() function is used to create a scalar type of tensor means. A scaler is a zero-dimension array and is also called a rank-0 Tensor. A scalar is created using .scalar() function.Syntax:t.scalar( value, dataType )Parameters:value: The value of the scalar. The value can be a number, string, Uint8Array[ ], boolean.dataType [Optional]: The data type of the value. It can be an int32, float32, bool, complex64, or string.Return Value: It returns the Tensor Object.Creating a Scalar: In this example, we are creating a new scalar, means a tensor of only one value.Example 1:JavascriptJavascript// Importing the tensorflow.js libraryimport * as tf from "@tensorflow/tfjs" // Value of a scalarvar value = 12 // Creating the value of a scalarvar tens = tf.scalar(value) // Printing the scalartens.print();  Output:Tensor
    12Creating a scalar of a specific data type: In this example, we are creating a scalar of a specific data type. Note that the data type should only int32, float32, bool, complex64, or string.Example 2:JavascriptJavascript// Importing the tensorflow.js libraryimport * as tf from "@tensorflow/tfjs" // Creating a scalar using int valuevar int_tensor = tf.scalar(12, 'int32') int_tensor.print() // Creating a scalar using string valuevar str_tensor = tf.scalar("GFG", "string") str_tensor.print() // Creating a scalar using float valuevar float_tensor = tf.scalar(12.6, "float32") float_tensor.print(); // Creating a scalar using bool valuevar bool_tensor1 = tf.scalar(true, "bool") bool_tensor1.print() // Creating a scalar using bool(0 and 1) typevar bool_tensor2 = tf.scalar(0, "bool") bool_tensor2.print()Output: Tensor
    12
Tensor
    GFG
Tensor
    12.600000381469727
Tensor
    true
Tensor
    falseNote: You can also create a scalar using tf.tensor() function. Let’s see the example Creating a Scalar using tf.tensor() Function: Example 3:JavascriptJavascript// Importing the tensorflow.js libraryimport * as tf from "@tensorflow/tfjs" // Creating a scalar using int tf.tensor()var tens = tf.tensor(12, [], "int32") tens.print()Here we are providing the second parameter of function an empty array because we are creating a scalar and a scalar is rank-0 tensor. Output:Tensor
    12 My Personal Notes
arrow_drop_upSave

Like0PreviousTensorFlow.js Browser Complete ReferenceNext
Tensorflow.js tf.backend() FunctionRecommended ArticlesPage :How to get the function name from within that function using JavaScript ?30, May 19How to call a function that return another function in JavaScript ?24, Jul 19How to get the function name inside a function in PHP ?25, Sep 19How to Check a Function is a Generator Function or not using JavaScript ?26, Mar 20How to implement a function that enable another function after specified time using JavaScript ?10, Mar 21How to create a function that invokes the provided function with its arguments transformed in JavaScript?18, Jul 21How to create a function that invokes each provided function with the arguments it receives using JavaScript ?25, May 21How to create a function that invokes function with partials prepended arguments in JavaScript ?26, Jul 21Difference between ‘function declaration’ and ‘function expression' in JavaScript20, Sep 21Difference between Function.prototype.apply and Function.prototype.call16, Nov 21Explain the differences on the usage of foo between function foo() {} and var foo = function() {}02, Mar 22How does TypeScript support optional parameters in function as every parameter is optional for a function in JavaScript ?24, Mar 22What are the advantages of synchronous function over asynchronous function in Node.js ?28, Mar 22How to create a function that invokes function with partials appended to the arguments in JavaScript ?28, May 21PHP | imagecreatetruecolor() Function18, Sep 18p5.js | year() function07, Apr 19D3.js | d3.utcTuesdays() Function24, Jul 19PHP | ImagickDraw getTextAlignment() Function16, Dec 19PHP | Ds\Sequence last() Function24, Jan 19Function to escape regex patterns before applied in PHP31, Oct 19PHP | array_udiff_uassoc() Function11, Jul 18PHP | geoip_continent_code_by_name() Function01, Jul 18D3.js | d3.map.set() Function27, Jun 19D3.js easePolyOut Function03, Sep 20Article Contributed By :_saurabh_jaiswal@_saurabh_jaiswalVote for difficultyEasy
Normal
Medium
Hard
ExpertImproved By :parasmadan15bunnyram19Article Tags :TensorflowJavaScriptWeb TechnologiesImprove ArticleReport IssueWriting code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Load CommentsWhat's NewInterview Series- Prepare, Practice & UpskillView DetailsData Structures & Algorithms- Self Paced CourseView DetailsComplete Interview PreparationView DetailsMost popular in JavaScriptRemove elements from a JavaScript ArrayConvert a string to an integer in JavaScriptDifference between var, let and const keywords in JavaScriptDifferences between Functional Components and Class Components in ReactHow to calculate the number of days between two dates in javascript?Most visited in Web TechnologiesRemove elements from a JavaScript ArrayInstallation of Node.js on LinuxConvert a string to an integer in JavaScriptHow to fetch data from an API in ReactJS ?Top 10 Projects For Beginners To Practice HTML and CSS SkillsImprove your Coding Skills with PracticeTry It!
5th Floor, A-118,Sector-136, Noida, Uttar Pradesh - 201305
feedback@geeksforgeeks.orgCompanyAbout UsCareersIn MediaContact UsPrivacy PolicyCopyright PolicyLearnAlgorithmsData StructuresSDE Cheat SheetMachine learningCS SubjectsVideo TutorialsNewsTop NewsTechnologyWork & CareerBusinessFinanceLifestyleLanguagesPythonJavaCPPGolangC#SQLWeb DevelopmentWeb TutorialsDjango TutorialHTMLCSSJavaScriptBootstrapContributeWrite an ArticleImprove an ArticlePick Topics to WriteWrite Interview ExperienceInternshipsVideo Internship@geeksforgeeks
, Some rights reserved 
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
        Privacy Policy

Got It !
Start Your Coding Journey Now!Login
Register
Tensorflow.js tf.tensor() Function
Tensorflow.js tf.scalar() Function
TenserFlow.js Tensors Creation Complete Reference
Tensorflow.js tf.Tensor class .buffer() Method
Tensorflow.js tf.Tensor class .bufferSync() Method
TensorFlow.js Tensors Classes Complete Reference
Tensorflow.js tf.booleanMaskAsync() Function
Tensorflow.js tf.concat() Function
TensorFlow.js Tensors Transformations Complete Reference
TensorFlow.js Slicing and Joining Complete Reference
Tensorflow.js tf.einsum() Function
Tensorflow.js tf.multinomial() Function
TensorFlow.js Tensor Random Complete Reference
Tensorflow.js tf.scalar() Function
Tensorflow.js tf.input() Function
Tensorflow.js tf.loadGraphModel() Function
Tensorflow.js tf.io.http() Function
TensorFlow.js Models Loading Complete Reference
Tensorflow.js tf.io.copyModel() Function
Tensorflow.js tf.io.listModels() Function
Tensorflow.js tf.io.moveModel() Function
TensorFlow.js Models Management Complete Reference
Tensorflow.js tf.GraphModel Class
Tensorflow.js tf.GraphModel class .save() Method
Tensorflow.js tf.GraphModel class .predict() Method
Tensorflow.js tf.GraphModel class .execute() Method
TensorFlow.js Models Classes Complete Reference
Tensorflow.js tf.scalar() Function
Tensorflow.js tf.layers.elu() Function
Tensorflow.js tf.layers.activation() Function
TensorFlow.js Layers Basic Complete Reference
Tensorflow.js tf.layers.conv1d() Function
TensorFlow.js Layers Convolutional Complete Reference
Tensorflow.js tf.layers.add() Function
TensorFlow.js Layers Merge Complete Reference
Tensorflow.js tf.layers.globalAveragePooling1d() Function
TensorFlow.js Layers Pooling Complete Reference
TensorFlow.js Layers Noise Complete Reference
Tensorflow.js tf.layers.bidirectional() Function
Tensorflow.js tf.layers.timeDistributed() Function
TensorFlow.js Layers Classes Complete Reference
Tensorflow.js tf.layers.zeroPadding2d() Function
Tensorflow.js tf.layers.masking() Function
Tensorflow.js tf.scalar() Function
TensorFlow.js Operations Arithmetic Complete Reference
TensorFlow.js Operations Basic Math Complete Reference
TensorFlow.js Operations Matrices Complete Reference
TensorFlow.js Operations Normalization Complete Reference
TensorFlow.js Operations Images Complete Reference
TensorFlow.js Operations Logical Complete Reference
TensorFlow.js Operations Evaluation Complete Reference
Tensorflow.js tf.cumsum() Function
TensorFlow.js Operations Slicing and Joining Complete Reference
TensorFlow.js Operations Spectral Complete Reference
Tensorflow.js tf.unsortedSegmentSum() Function
Tensorflow.js tf.movingAverage() Function
Tensorflow.js tf.dropout() Function
TensorFlow.js Operations Signal Complete Reference
Tensorflow.js tf.linalg.bandPart() Function
Tensorflow.js tf.linalg.gramSchmidt() Function
Tensorflow.js tf.linalg.qr() Function
TensorFlow.js Operations Sparse Complete Reference
Tensorflow.js tf.scalar() Function
Tensorflow.js tf.grad() Function
Tensorflow.js tf.grads() Function
Tensorflow.js tf.customGrad() Function
TensorFlow.js Training Gradients Complete ReferenceTensorflow.js TrainingTensorflow.js tf.train.momentum() FunctionTensorflow.js tf.train.adagrad() FunctionTensorFlow.js Training Optimizers Complete ReferenceTensorflow.js tf.losses.absoluteDifference() FunctionTensorflow.js tf.losses.computeWeightedLoss() FunctionTensorflow.js tf.losses.cosineDistance() FunctionTensorFlow.js Training Losses Complete ReferenceTensorflow.js tf.train.Optimizer ClassTensorflow.js tf.train.Optimizer class .minimize() MethodTensorFlow.js Training Classes Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js tf.time() FunctionTensorflow.js tf.nextFrame() FunctionTensorflow.js tf.profile() FunctionTensorFlow.js Performance Memory Complete ReferenceTensorflow.js PerformanceTensorflow.js tf.disposeVariables() FunctionTensorflow.js tf.enableDebugMode() FunctionTensorflow.js tf.enableProdMode() FunctionTensorflow.js tf.engine() FunctionTensorflow.js EnvironmentTensorFlow.js Environment Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js tf.metrics.binaryAccuracy() FunctionTensorflow.js tf.metrics.binaryCrossentropy() FunctionTensorflow.js tf.metrics.categoricalAccuracy() FunctionTensorflow.js tf.metrics.categoricalCrossentropy() FunctionTensorflow.js tf.metrics.cosineProximity() FunctionTensorflow.js ConstraintsTensorflow.js tf.metrics.meanSquaredError() FunctionTensorflow.js tf.metrics.precision() FunctionTensorflow.js tf.metrics.recall() FunctionTensorflow.js tf.metrics.sparseCategoricalAccuracy() FunctionTensorFlow.js Metrics Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js tf.initializers.Initializer ClassTensorflow.js tf.initializers.constant() MethodTensorflow.js tf.initializers.glorotNormal() FunctionTensorflow.js tf.initializers.glorotUniform() FunctionTensorflow.js tf.initializers.heNormal() FunctionTensorflow.js tf.initializers.heUniform() FunctionTensorflow.js InitializersTensorFlow.js Initializers Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js tf.regularizers.l1() FunctionTensorflow.js tf.regularizers.l1l2() FunctionTensorflow.js tf.regularizers.l2() FunctionTensorflow.js tf.scalar() FunctionTensorflow.js tf.data.csv() FunctionTensorflow.js tf.data.generator() FunctionTensorflow.js tf.data.microphone() FunctionTensorflow.js RegularizesTensorFlow.js Data Creation Complete ReferenceTensorflow.js tf.data.zip() FunctionTensorflow.js tf.data.Dataset class .batch() MethodTensorflow.js DataTensorFlow.js Data Classes Complete ReferencesTensorflow.js tf.scalar() FunctionTensorflow.js tf.util.assert() FunctionTensorflow.js tf.util.createShuffledIndices() FunctionTensorflow.js tf.decodeString() FunctionTensorflow.js tf.encodeString() FunctionTensorflow.js tf.fetch() FunctionTensorflow.js tf.util.flatten() FunctionTensorflow.js tf.util.now() FunctionTensorflow.js tf.util.shuffle() FunctionTensorflow.js tf.util.shuffleCombo() FunctionTensorflow.js UtilTensorflow.js tf.browser.fromPixels() FunctionTensorflow.js tf.browser.fromPixelsAsync() FunctionTensorflow.js tf.browser.toPixels() FunctionTensorFlow.js Browser Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js tf.backend() FunctionTensorflow.js tf.getBackend() FunctionTensorflow.js tf.ready() FunctionTensorflow.js tf.registerBackend() FunctionTensorflow.js tf.removeBackend() FunctionTensorflow.js tf.setBackend() FunctionTensorflow.js BrowserTensorflow.js tf.callbacks.earlyStopping() FunctionTensorflow.js BackendsTensorflow.js MetricsTable of ContentsTensorFlow.jsTensorflow.js IntroductionTensorflow.js TensorsTensorflow.js tf.tensor() FunctionTensorflow.js tf.scalar() FunctionTenserFlow.js Tensors Creation Complete ReferenceTensorflow.js tf.Tensor class .buffer() MethodTensorflow.js tf.Tensor class .bufferSync() MethodTensorFlow.js Tensors Classes Complete ReferenceTensorflow.js tf.booleanMaskAsync() FunctionTensorflow.js tf.concat() FunctionTensorFlow.js Tensors Transformations Complete ReferenceTensorFlow.js Slicing and Joining Complete ReferenceTensorflow.js tf.einsum() FunctionTensorflow.js tf.multinomial() FunctionTensorFlow.js Tensor Random Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js ModelsTensorflow.js tf.input() FunctionTensorflow.js tf.loadGraphModel() FunctionTensorflow.js tf.io.http() FunctionTensorFlow.js Models Loading Complete ReferenceTensorflow.js tf.io.copyModel() FunctionTensorflow.js tf.io.listModels() FunctionTensorflow.js tf.io.moveModel() FunctionTensorFlow.js Models Management Complete ReferenceTensorflow.js tf.GraphModel ClassTensorflow.js tf.GraphModel class .save() MethodTensorflow.js tf.GraphModel class .predict() MethodTensorflow.js tf.GraphModel class .execute() MethodTensorFlow.js Models Classes Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js tf.layers.elu() FunctionTensorflow.js LayersTensorflow.js tf.layers.activation() FunctionTensorFlow.js Layers Basic Complete ReferenceTensorflow.js tf.layers.conv1d() FunctionTensorFlow.js Layers Convolutional Complete ReferenceTensorflow.js tf.layers.add() FunctionTensorFlow.js Layers Merge Complete ReferenceTensorflow.js tf.layers.globalAveragePooling1d() FunctionTensorFlow.js Layers Pooling Complete ReferenceTensorFlow.js Layers Noise Complete ReferenceTensorflow.js tf.layers.bidirectional() FunctionTensorflow.js tf.layers.timeDistributed() FunctionTensorFlow.js Layers Classes Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.layers.masking() FunctionTensorflow.js tf.scalar() FunctionTensorFlow.js Operations Arithmetic Complete ReferenceTensorFlow.js Operations Basic Math Complete ReferenceTensorFlow.js Operations Matrices Complete ReferenceTensorflow.js OperationsTensorFlow.js Operations Normalization Complete ReferenceTensorFlow.js Operations Images Complete ReferenceTensorFlow.js Operations Logical Complete ReferenceTensorFlow.js Operations Evaluation Complete ReferenceTensorflow.js tf.cumsum() FunctionTensorFlow.js Operations Slicing and Joining Complete ReferenceTensorFlow.js Operations Spectral Complete ReferenceTensorflow.js tf.unsortedSegmentSum() FunctionTensorflow.js tf.movingAverage() FunctionTensorflow.js tf.dropout() FunctionTensorFlow.js Operations Signal Complete ReferenceTensorflow.js tf.linalg.bandPart() FunctionTensorflow.js tf.linalg.gramSchmidt() FunctionTensorflow.js tf.linalg.qr() FunctionTensorFlow.js Operations Sparse Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js tf.grad() FunctionTensorflow.js tf.grads() FunctionTensorflow.js tf.customGrad() FunctionTensorFlow.js Training Gradients Complete ReferenceTensorflow.js TrainingTensorflow.js tf.train.momentum() FunctionTensorflow.js tf.train.adagrad() FunctionTensorFlow.js Training Optimizers Complete ReferenceTensorflow.js tf.losses.absoluteDifference() FunctionTensorflow.js tf.losses.computeWeightedLoss() FunctionTensorflow.js tf.losses.cosineDistance() FunctionTensorFlow.js Training Losses Complete ReferenceTensorflow.js tf.train.Optimizer ClassTensorflow.js tf.train.Optimizer class .minimize() MethodTensorFlow.js Training Classes Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js tf.time() FunctionTensorflow.js tf.nextFrame() FunctionTensorflow.js tf.profile() FunctionTensorFlow.js Performance Memory Complete ReferenceTensorflow.js PerformanceTensorflow.js tf.disposeVariables() FunctionTensorflow.js tf.enableDebugMode() FunctionTensorflow.js tf.enableProdMode() FunctionTensorflow.js tf.engine() FunctionTensorflow.js EnvironmentTensorFlow.js Environment Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js tf.metrics.binaryAccuracy() FunctionTensorflow.js tf.metrics.binaryCrossentropy() FunctionTensorflow.js tf.metrics.categoricalAccuracy() FunctionTensorflow.js tf.metrics.categoricalCrossentropy() FunctionTensorflow.js tf.metrics.cosineProximity() FunctionTensorflow.js ConstraintsTensorflow.js tf.metrics.meanSquaredError() FunctionTensorflow.js tf.metrics.precision() FunctionTensorflow.js tf.metrics.recall() FunctionTensorflow.js tf.metrics.sparseCategoricalAccuracy() FunctionTensorFlow.js Metrics Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js tf.initializers.Initializer ClassTensorflow.js tf.initializers.constant() MethodTensorflow.js tf.initializers.glorotNormal() FunctionTensorflow.js tf.initializers.glorotUniform() FunctionTensorflow.js tf.initializers.heNormal() FunctionTensorflow.js tf.initializers.heUniform() FunctionTensorflow.js InitializersTensorFlow.js Initializers Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js tf.regularizers.l1() FunctionTensorflow.js tf.regularizers.l1l2() FunctionTensorflow.js tf.regularizers.l2() FunctionTensorflow.js tf.scalar() FunctionTensorflow.js tf.data.csv() FunctionTensorflow.js tf.data.generator() FunctionTensorflow.js tf.data.microphone() FunctionTensorflow.js RegularizesTensorFlow.js Data Creation Complete ReferenceTensorflow.js tf.data.zip() FunctionTensorflow.js tf.data.Dataset class .batch() MethodTensorflow.js DataTensorFlow.js Data Classes Complete ReferencesTensorflow.js tf.scalar() FunctionTensorflow.js tf.util.assert() FunctionTensorflow.js tf.util.createShuffledIndices() FunctionTensorflow.js tf.decodeString() FunctionTensorflow.js tf.encodeString() FunctionTensorflow.js tf.fetch() FunctionTensorflow.js tf.util.flatten() FunctionTensorflow.js tf.util.now() FunctionTensorflow.js tf.util.shuffle() FunctionTensorflow.js tf.util.shuffleCombo() FunctionTensorflow.js UtilTensorflow.js tf.browser.fromPixels() FunctionTensorflow.js tf.browser.fromPixelsAsync() FunctionTensorflow.js tf.browser.toPixels() FunctionTensorFlow.js Browser Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js tf.backend() FunctionTensorflow.js tf.getBackend() FunctionTensorflow.js tf.ready() FunctionTensorflow.js tf.registerBackend() FunctionTensorflow.js tf.removeBackend() FunctionTensorflow.js tf.setBackend() FunctionTensorflow.js BrowserTensorflow.js tf.callbacks.earlyStopping() FunctionTensorflow.js BackendsTensorflow.js MetricsImprove Article

Save Article

Like Article

Tensorflow.js tf.scalar() FunctionLast Updated :
13 May, 2021Tensorflow.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 .scalar() function is used to create a scalar type of tensor means. A scaler is a zero-dimension array and is also called a rank-0 Tensor. A scalar is created using .scalar() function.Syntax:t.scalar( value, dataType )Parameters:value: The value of the scalar. The value can be a number, string, Uint8Array[ ], boolean.dataType [Optional]: The data type of the value. It can be an int32, float32, bool, complex64, or string.Return Value: It returns the Tensor Object.Creating a Scalar: In this example, we are creating a new scalar, means a tensor of only one value.Example 1:JavascriptJavascript// Importing the tensorflow.js libraryimport * as tf from "@tensorflow/tfjs" // Value of a scalarvar value = 12 // Creating the value of a scalarvar tens = tf.scalar(value) // Printing the scalartens.print();  Output:Tensor
    12Creating a scalar of a specific data type: In this example, we are creating a scalar of a specific data type. Note that the data type should only int32, float32, bool, complex64, or string.Example 2:JavascriptJavascript// Importing the tensorflow.js libraryimport * as tf from "@tensorflow/tfjs" // Creating a scalar using int valuevar int_tensor = tf.scalar(12, 'int32') int_tensor.print() // Creating a scalar using string valuevar str_tensor = tf.scalar("GFG", "string") str_tensor.print() // Creating a scalar using float valuevar float_tensor = tf.scalar(12.6, "float32") float_tensor.print(); // Creating a scalar using bool valuevar bool_tensor1 = tf.scalar(true, "bool") bool_tensor1.print() // Creating a scalar using bool(0 and 1) typevar bool_tensor2 = tf.scalar(0, "bool") bool_tensor2.print()Output: Tensor
    12
Tensor
    GFG
Tensor
    12.600000381469727
Tensor
    true
Tensor
    falseNote: You can also create a scalar using tf.tensor() function. Let’s see the example Creating a Scalar using tf.tensor() Function: Example 3:JavascriptJavascript// Importing the tensorflow.js libraryimport * as tf from "@tensorflow/tfjs" // Creating a scalar using int tf.tensor()var tens = tf.tensor(12, [], "int32") tens.print()Here we are providing the second parameter of function an empty array because we are creating a scalar and a scalar is rank-0 tensor. Output:Tensor
    12 My Personal Notes
arrow_drop_upSave

Like0PreviousTensorFlow.js Browser Complete ReferenceNext
Tensorflow.js tf.backend() FunctionRecommended ArticlesPage :How to get the function name from within that function using JavaScript ?30, May 19How to call a function that return another function in JavaScript ?24, Jul 19How to get the function name inside a function in PHP ?25, Sep 19How to Check a Function is a Generator Function or not using JavaScript ?26, Mar 20How to implement a function that enable another function after specified time using JavaScript ?10, Mar 21How to create a function that invokes the provided function with its arguments transformed in JavaScript?18, Jul 21How to create a function that invokes each provided function with the arguments it receives using JavaScript ?25, May 21How to create a function that invokes function with partials prepended arguments in JavaScript ?26, Jul 21Difference between ‘function declaration’ and ‘function expression' in JavaScript20, Sep 21Difference between Function.prototype.apply and Function.prototype.call16, Nov 21Explain the differences on the usage of foo between function foo() {} and var foo = function() {}02, Mar 22How does TypeScript support optional parameters in function as every parameter is optional for a function in JavaScript ?24, Mar 22What are the advantages of synchronous function over asynchronous function in Node.js ?28, Mar 22How to create a function that invokes function with partials appended to the arguments in JavaScript ?28, May 21PHP | imagecreatetruecolor() Function18, Sep 18p5.js | year() function07, Apr 19D3.js | d3.utcTuesdays() Function24, Jul 19PHP | ImagickDraw getTextAlignment() Function16, Dec 19PHP | Ds\Sequence last() Function24, Jan 19Function to escape regex patterns before applied in PHP31, Oct 19PHP | array_udiff_uassoc() Function11, Jul 18PHP | geoip_continent_code_by_name() Function01, Jul 18D3.js | d3.map.set() Function27, Jun 19D3.js easePolyOut Function03, Sep 20Article Contributed By :_saurabh_jaiswal@_saurabh_jaiswalVote for difficultyEasy
Normal
Medium
Hard
ExpertImproved By :parasmadan15bunnyram19Article Tags :TensorflowJavaScriptWeb TechnologiesImprove ArticleReport IssueWriting code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Load CommentsWhat's NewInterview Series- Prepare, Practice & UpskillView DetailsData Structures & Algorithms- Self Paced CourseView DetailsComplete Interview PreparationView DetailsMost popular in JavaScriptRemove elements from a JavaScript ArrayConvert a string to an integer in JavaScriptDifference between var, let and const keywords in JavaScriptDifferences between Functional Components and Class Components in ReactHow to calculate the number of days between two dates in javascript?Most visited in Web TechnologiesRemove elements from a JavaScript ArrayInstallation of Node.js on LinuxConvert a string to an integer in JavaScriptHow to fetch data from an API in ReactJS ?Top 10 Projects For Beginners To Practice HTML and CSS SkillsImprove your Coding Skills with PracticeTry It!
5th Floor, A-118,Sector-136, Noida, Uttar Pradesh - 201305
feedback@geeksforgeeks.orgCompanyAbout UsCareersIn MediaContact UsPrivacy PolicyCopyright PolicyLearnAlgorithmsData StructuresSDE Cheat SheetMachine learningCS SubjectsVideo TutorialsNewsTop NewsTechnologyWork & CareerBusinessFinanceLifestyleLanguagesPythonJavaCPPGolangC#SQLWeb DevelopmentWeb TutorialsDjango TutorialHTMLCSSJavaScriptBootstrapContributeWrite an ArticleImprove an ArticlePick Topics to WriteWrite Interview ExperienceInternshipsVideo Internship@geeksforgeeks
, Some rights reserved 
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
        Privacy Policy

Got It !
Start Your Coding Journey Now!Login
Register
Tensorflow.js tf.train.momentum() Function
Tensorflow.js tf.train.adagrad() Function
TensorFlow.js Training Optimizers Complete Reference
Tensorflow.js tf.losses.absoluteDifference() Function
Tensorflow.js tf.losses.computeWeightedLoss() Function
Tensorflow.js tf.losses.cosineDistance() Function
TensorFlow.js Training Losses Complete Reference
Tensorflow.js tf.train.Optimizer Class
Tensorflow.js tf.train.Optimizer class .minimize() Method
TensorFlow.js Training Classes Complete Reference
Tensorflow.js tf.scalar() Function
Tensorflow.js tf.time() Function
Tensorflow.js tf.nextFrame() Function
Tensorflow.js tf.profile() Function
TensorFlow.js Performance Memory Complete Reference
Tensorflow.js tf.disposeVariables() Function
Tensorflow.js tf.enableDebugMode() Function
Tensorflow.js tf.enableProdMode() Function
Tensorflow.js tf.engine() FunctionTensorflow.js EnvironmentTensorFlow.js Environment Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js tf.metrics.binaryAccuracy() FunctionTensorflow.js tf.metrics.binaryCrossentropy() FunctionTensorflow.js tf.metrics.categoricalAccuracy() FunctionTensorflow.js tf.metrics.categoricalCrossentropy() FunctionTensorflow.js tf.metrics.cosineProximity() FunctionTensorflow.js ConstraintsTensorflow.js tf.metrics.meanSquaredError() FunctionTensorflow.js tf.metrics.precision() FunctionTensorflow.js tf.metrics.recall() FunctionTensorflow.js tf.metrics.sparseCategoricalAccuracy() FunctionTensorFlow.js Metrics Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js tf.initializers.Initializer ClassTensorflow.js tf.initializers.constant() MethodTensorflow.js tf.initializers.glorotNormal() FunctionTensorflow.js tf.initializers.glorotUniform() FunctionTensorflow.js tf.initializers.heNormal() FunctionTensorflow.js tf.initializers.heUniform() FunctionTensorflow.js InitializersTensorFlow.js Initializers Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js tf.regularizers.l1() FunctionTensorflow.js tf.regularizers.l1l2() FunctionTensorflow.js tf.regularizers.l2() FunctionTensorflow.js tf.scalar() FunctionTensorflow.js tf.data.csv() FunctionTensorflow.js tf.data.generator() FunctionTensorflow.js tf.data.microphone() FunctionTensorflow.js RegularizesTensorFlow.js Data Creation Complete ReferenceTensorflow.js tf.data.zip() FunctionTensorflow.js tf.data.Dataset class .batch() MethodTensorflow.js DataTensorFlow.js Data Classes Complete ReferencesTensorflow.js tf.scalar() FunctionTensorflow.js tf.util.assert() FunctionTensorflow.js tf.util.createShuffledIndices() FunctionTensorflow.js tf.decodeString() FunctionTensorflow.js tf.encodeString() FunctionTensorflow.js tf.fetch() FunctionTensorflow.js tf.util.flatten() FunctionTensorflow.js tf.util.now() FunctionTensorflow.js tf.util.shuffle() FunctionTensorflow.js tf.util.shuffleCombo() FunctionTensorflow.js UtilTensorflow.js tf.browser.fromPixels() FunctionTensorflow.js tf.browser.fromPixelsAsync() FunctionTensorflow.js tf.browser.toPixels() FunctionTensorFlow.js Browser Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js tf.backend() FunctionTensorflow.js tf.getBackend() FunctionTensorflow.js tf.ready() FunctionTensorflow.js tf.registerBackend() FunctionTensorflow.js tf.removeBackend() FunctionTensorflow.js tf.setBackend() FunctionTensorflow.js BrowserTensorflow.js tf.callbacks.earlyStopping() FunctionTensorflow.js BackendsTensorflow.js Metrics
TensorFlow.js Environment Complete Reference
Tensorflow.js tf.scalar() Function
Tensorflow.js tf.metrics.binaryAccuracy() Function
Tensorflow.js tf.metrics.binaryCrossentropy() Function
Tensorflow.js tf.metrics.categoricalAccuracy() Function
Tensorflow.js tf.metrics.categoricalCrossentropy() Function
Tensorflow.js tf.metrics.cosineProximity() Function
Tensorflow.js tf.metrics.meanSquaredError() Function
Tensorflow.js tf.metrics.precision() Function
Tensorflow.js tf.metrics.recall() Function
Tensorflow.js tf.metrics.sparseCategoricalAccuracy() Function
TensorFlow.js Metrics Complete Reference
Tensorflow.js tf.scalar() Function
Tensorflow.js tf.initializers.Initializer Class
Tensorflow.js tf.initializers.constant() Method
Tensorflow.js tf.initializers.glorotNormal() Function
Tensorflow.js tf.initializers.glorotUniform() Function
Tensorflow.js tf.initializers.heNormal() Function
Tensorflow.js tf.initializers.heUniform() Function
TensorFlow.js Initializers Complete Reference
Tensorflow.js tf.scalar() Function
Tensorflow.js tf.regularizers.l1() Function
Tensorflow.js tf.regularizers.l1l2() Function
Tensorflow.js tf.regularizers.l2() Function
Tensorflow.js tf.scalar() Function
Tensorflow.js tf.data.csv() Function
Tensorflow.js tf.data.generator() Function
Tensorflow.js tf.data.microphone() FunctionTensorflow.js RegularizesTensorFlow.js Data Creation Complete ReferenceTensorflow.js tf.data.zip() FunctionTensorflow.js tf.data.Dataset class .batch() MethodTensorflow.js DataTensorFlow.js Data Classes Complete ReferencesTensorflow.js tf.scalar() FunctionTensorflow.js tf.util.assert() FunctionTensorflow.js tf.util.createShuffledIndices() FunctionTensorflow.js tf.decodeString() FunctionTensorflow.js tf.encodeString() FunctionTensorflow.js tf.fetch() FunctionTensorflow.js tf.util.flatten() FunctionTensorflow.js tf.util.now() FunctionTensorflow.js tf.util.shuffle() FunctionTensorflow.js tf.util.shuffleCombo() FunctionTensorflow.js UtilTensorflow.js tf.browser.fromPixels() FunctionTensorflow.js tf.browser.fromPixelsAsync() FunctionTensorflow.js tf.browser.toPixels() FunctionTensorFlow.js Browser Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js tf.backend() FunctionTensorflow.js tf.getBackend() FunctionTensorflow.js tf.ready() FunctionTensorflow.js tf.registerBackend() FunctionTensorflow.js tf.removeBackend() FunctionTensorflow.js tf.setBackend() FunctionTensorflow.js BrowserTensorflow.js tf.callbacks.earlyStopping() FunctionTensorflow.js BackendsTensorflow.js Metrics
TensorFlow.js Data Creation Complete Reference
Tensorflow.js tf.data.zip() Function
Tensorflow.js tf.data.Dataset class .batch() Method
TensorFlow.js Data Classes Complete References
Tensorflow.js tf.scalar() Function
Tensorflow.js tf.util.assert() Function
Tensorflow.js tf.util.createShuffledIndices() Function
Tensorflow.js tf.decodeString() Function
Tensorflow.js tf.encodeString() Function
Tensorflow.js tf.fetch() Function
Tensorflow.js tf.util.flatten() Function
Tensorflow.js tf.util.now() Function
Tensorflow.js tf.util.shuffle() Function
Tensorflow.js tf.util.shuffleCombo() Function
Tensorflow.js tf.browser.fromPixels() Function
Tensorflow.js tf.browser.fromPixelsAsync() Function
Tensorflow.js tf.browser.toPixels() Function
TensorFlow.js Browser Complete Reference
Tensorflow.js tf.scalar() Function
Tensorflow.js tf.backend() Function
Tensorflow.js tf.getBackend() Function
Tensorflow.js tf.ready() Function
Tensorflow.js tf.registerBackend() Function
Tensorflow.js tf.removeBackend() Function
Tensorflow.js tf.setBackend() Function
Tensorflow.js tf.callbacks.earlyStopping() Function
TensorFlow.js
Tensorflow.js IntroductionTensorflow.js TensorsTensorflow.js tf.tensor() FunctionTensorflow.js tf.scalar() FunctionTenserFlow.js Tensors Creation Complete ReferenceTensorflow.js tf.Tensor class .buffer() MethodTensorflow.js tf.Tensor class .bufferSync() MethodTensorFlow.js Tensors Classes Complete ReferenceTensorflow.js tf.booleanMaskAsync() FunctionTensorflow.js tf.concat() FunctionTensorFlow.js Tensors Transformations Complete ReferenceTensorFlow.js Slicing and Joining Complete ReferenceTensorflow.js tf.einsum() FunctionTensorflow.js tf.multinomial() FunctionTensorFlow.js Tensor Random Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js ModelsTensorflow.js tf.input() FunctionTensorflow.js tf.loadGraphModel() FunctionTensorflow.js tf.io.http() FunctionTensorFlow.js Models Loading Complete ReferenceTensorflow.js tf.io.copyModel() FunctionTensorflow.js tf.io.listModels() FunctionTensorflow.js tf.io.moveModel() FunctionTensorFlow.js Models Management Complete ReferenceTensorflow.js tf.GraphModel ClassTensorflow.js tf.GraphModel class .save() MethodTensorflow.js tf.GraphModel class .predict() MethodTensorflow.js tf.GraphModel class .execute() MethodTensorFlow.js Models Classes Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js tf.layers.elu() FunctionTensorflow.js LayersTensorflow.js tf.layers.activation() FunctionTensorFlow.js Layers Basic Complete ReferenceTensorflow.js tf.layers.conv1d() FunctionTensorFlow.js Layers Convolutional Complete ReferenceTensorflow.js tf.layers.add() FunctionTensorFlow.js Layers Merge Complete ReferenceTensorflow.js tf.layers.globalAveragePooling1d() FunctionTensorFlow.js Layers Pooling Complete ReferenceTensorFlow.js Layers Noise Complete ReferenceTensorflow.js tf.layers.bidirectional() FunctionTensorflow.js tf.layers.timeDistributed() FunctionTensorFlow.js Layers Classes Complete ReferenceTensorflow.js tf.layers.zeroPadding2d() FunctionTensorflow.js tf.layers.masking() FunctionTensorflow.js tf.scalar() FunctionTensorFlow.js Operations Arithmetic Complete ReferenceTensorFlow.js Operations Basic Math Complete ReferenceTensorFlow.js Operations Matrices Complete ReferenceTensorflow.js OperationsTensorFlow.js Operations Normalization Complete ReferenceTensorFlow.js Operations Images Complete ReferenceTensorFlow.js Operations Logical Complete ReferenceTensorFlow.js Operations Evaluation Complete ReferenceTensorflow.js tf.cumsum() FunctionTensorFlow.js Operations Slicing and Joining Complete ReferenceTensorFlow.js Operations Spectral Complete ReferenceTensorflow.js tf.unsortedSegmentSum() FunctionTensorflow.js tf.movingAverage() FunctionTensorflow.js tf.dropout() FunctionTensorFlow.js Operations Signal Complete ReferenceTensorflow.js tf.linalg.bandPart() FunctionTensorflow.js tf.linalg.gramSchmidt() FunctionTensorflow.js tf.linalg.qr() FunctionTensorFlow.js Operations Sparse Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js tf.grad() FunctionTensorflow.js tf.grads() FunctionTensorflow.js tf.customGrad() FunctionTensorFlow.js Training Gradients Complete ReferenceTensorflow.js TrainingTensorflow.js tf.train.momentum() FunctionTensorflow.js tf.train.adagrad() FunctionTensorFlow.js Training Optimizers Complete ReferenceTensorflow.js tf.losses.absoluteDifference() FunctionTensorflow.js tf.losses.computeWeightedLoss() FunctionTensorflow.js tf.losses.cosineDistance() FunctionTensorFlow.js Training Losses Complete ReferenceTensorflow.js tf.train.Optimizer ClassTensorflow.js tf.train.Optimizer class .minimize() MethodTensorFlow.js Training Classes Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js tf.time() FunctionTensorflow.js tf.nextFrame() FunctionTensorflow.js tf.profile() FunctionTensorFlow.js Performance Memory Complete ReferenceTensorflow.js PerformanceTensorflow.js tf.disposeVariables() FunctionTensorflow.js tf.enableDebugMode() FunctionTensorflow.js tf.enableProdMode() FunctionTensorflow.js tf.engine() FunctionTensorflow.js EnvironmentTensorFlow.js Environment Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js tf.metrics.binaryAccuracy() FunctionTensorflow.js tf.metrics.binaryCrossentropy() FunctionTensorflow.js tf.metrics.categoricalAccuracy() FunctionTensorflow.js tf.metrics.categoricalCrossentropy() FunctionTensorflow.js tf.metrics.cosineProximity() FunctionTensorflow.js ConstraintsTensorflow.js tf.metrics.meanSquaredError() FunctionTensorflow.js tf.metrics.precision() FunctionTensorflow.js tf.metrics.recall() FunctionTensorflow.js tf.metrics.sparseCategoricalAccuracy() FunctionTensorFlow.js Metrics Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js tf.initializers.Initializer ClassTensorflow.js tf.initializers.constant() MethodTensorflow.js tf.initializers.glorotNormal() FunctionTensorflow.js tf.initializers.glorotUniform() FunctionTensorflow.js tf.initializers.heNormal() FunctionTensorflow.js tf.initializers.heUniform() FunctionTensorflow.js InitializersTensorFlow.js Initializers Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js tf.regularizers.l1() FunctionTensorflow.js tf.regularizers.l1l2() FunctionTensorflow.js tf.regularizers.l2() FunctionTensorflow.js tf.scalar() FunctionTensorflow.js tf.data.csv() FunctionTensorflow.js tf.data.generator() FunctionTensorflow.js tf.data.microphone() FunctionTensorflow.js RegularizesTensorFlow.js Data Creation Complete ReferenceTensorflow.js tf.data.zip() FunctionTensorflow.js tf.data.Dataset class .batch() MethodTensorflow.js DataTensorFlow.js Data Classes Complete ReferencesTensorflow.js tf.scalar() FunctionTensorflow.js tf.util.assert() FunctionTensorflow.js tf.util.createShuffledIndices() FunctionTensorflow.js tf.decodeString() FunctionTensorflow.js tf.encodeString() FunctionTensorflow.js tf.fetch() FunctionTensorflow.js tf.util.flatten() FunctionTensorflow.js tf.util.now() FunctionTensorflow.js tf.util.shuffle() FunctionTensorflow.js tf.util.shuffleCombo() FunctionTensorflow.js UtilTensorflow.js tf.browser.fromPixels() FunctionTensorflow.js tf.browser.fromPixelsAsync() FunctionTensorflow.js tf.browser.toPixels() FunctionTensorFlow.js Browser Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js tf.backend() FunctionTensorflow.js tf.getBackend() FunctionTensorflow.js tf.ready() FunctionTensorflow.js tf.registerBackend() FunctionTensorflow.js tf.removeBackend() FunctionTensorflow.js tf.setBackend() FunctionTensorflow.js BrowserTensorflow.js tf.callbacks.earlyStopping() FunctionTensorflow.js BackendsTensorflow.js MetricsImprove Article

Save Article

Like Article

Tensorflow.js tf.scalar() FunctionLast Updated :
13 May, 2021Tensorflow.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 .scalar() function is used to create a scalar type of tensor means. A scaler is a zero-dimension array and is also called a rank-0 Tensor. A scalar is created using .scalar() function.Syntax:t.scalar( value, dataType )Parameters:value: The value of the scalar. The value can be a number, string, Uint8Array[ ], boolean.dataType [Optional]: The data type of the value. It can be an int32, float32, bool, complex64, or string.Return Value: It returns the Tensor Object.Creating a Scalar: In this example, we are creating a new scalar, means a tensor of only one value.Example 1:JavascriptJavascript// Importing the tensorflow.js libraryimport * as tf from "@tensorflow/tfjs" // Value of a scalarvar value = 12 // Creating the value of a scalarvar tens = tf.scalar(value) // Printing the scalartens.print();  Output:Tensor
    12Creating a scalar of a specific data type: In this example, we are creating a scalar of a specific data type. Note that the data type should only int32, float32, bool, complex64, or string.Example 2:JavascriptJavascript// Importing the tensorflow.js libraryimport * as tf from "@tensorflow/tfjs" // Creating a scalar using int valuevar int_tensor = tf.scalar(12, 'int32') int_tensor.print() // Creating a scalar using string valuevar str_tensor = tf.scalar("GFG", "string") str_tensor.print() // Creating a scalar using float valuevar float_tensor = tf.scalar(12.6, "float32") float_tensor.print(); // Creating a scalar using bool valuevar bool_tensor1 = tf.scalar(true, "bool") bool_tensor1.print() // Creating a scalar using bool(0 and 1) typevar bool_tensor2 = tf.scalar(0, "bool") bool_tensor2.print()Output: Tensor
    12
Tensor
    GFG
Tensor
    12.600000381469727
Tensor
    true
Tensor
    falseNote: You can also create a scalar using tf.tensor() function. Let’s see the example Creating a Scalar using tf.tensor() Function: Example 3:JavascriptJavascript// Importing the tensorflow.js libraryimport * as tf from "@tensorflow/tfjs" // Creating a scalar using int tf.tensor()var tens = tf.tensor(12, [], "int32") tens.print()Here we are providing the second parameter of function an empty array because we are creating a scalar and a scalar is rank-0 tensor. Output:Tensor
    12 My Personal Notes
arrow_drop_upSave

Like0PreviousTensorFlow.js Browser Complete ReferenceNext
Tensorflow.js tf.backend() FunctionRecommended ArticlesPage :How to get the function name from within that function using JavaScript ?30, May 19How to call a function that return another function in JavaScript ?24, Jul 19How to get the function name inside a function in PHP ?25, Sep 19How to Check a Function is a Generator Function or not using JavaScript ?26, Mar 20How to implement a function that enable another function after specified time using JavaScript ?10, Mar 21How to create a function that invokes the provided function with its arguments transformed in JavaScript?18, Jul 21How to create a function that invokes each provided function with the arguments it receives using JavaScript ?25, May 21How to create a function that invokes function with partials prepended arguments in JavaScript ?26, Jul 21Difference between ‘function declaration’ and ‘function expression' in JavaScript20, Sep 21Difference between Function.prototype.apply and Function.prototype.call16, Nov 21Explain the differences on the usage of foo between function foo() {} and var foo = function() {}02, Mar 22How does TypeScript support optional parameters in function as every parameter is optional for a function in JavaScript ?24, Mar 22What are the advantages of synchronous function over asynchronous function in Node.js ?28, Mar 22How to create a function that invokes function with partials appended to the arguments in JavaScript ?28, May 21PHP | imagecreatetruecolor() Function18, Sep 18p5.js | year() function07, Apr 19D3.js | d3.utcTuesdays() Function24, Jul 19PHP | ImagickDraw getTextAlignment() Function16, Dec 19PHP | Ds\Sequence last() Function24, Jan 19Function to escape regex patterns before applied in PHP31, Oct 19PHP | array_udiff_uassoc() Function11, Jul 18PHP | geoip_continent_code_by_name() Function01, Jul 18D3.js | d3.map.set() Function27, Jun 19D3.js easePolyOut Function03, Sep 20Article Contributed By :_saurabh_jaiswal@_saurabh_jaiswalVote for difficultyEasy
Normal
Medium
Hard
ExpertImproved By :parasmadan15bunnyram19Article Tags :TensorflowJavaScriptWeb TechnologiesImprove ArticleReport IssueWriting code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Load CommentsWhat's NewInterview Series- Prepare, Practice & UpskillView DetailsData Structures & Algorithms- Self Paced CourseView DetailsComplete Interview PreparationView DetailsMost popular in JavaScriptRemove elements from a JavaScript ArrayConvert a string to an integer in JavaScriptDifference between var, let and const keywords in JavaScriptDifferences between Functional Components and Class Components in ReactHow to calculate the number of days between two dates in javascript?Most visited in Web TechnologiesRemove elements from a JavaScript ArrayInstallation of Node.js on LinuxConvert a string to an integer in JavaScriptHow to fetch data from an API in ReactJS ?Top 10 Projects For Beginners To Practice HTML and CSS Skills
Tensorflow.js tf.tensor() Function
Tensorflow.js tf.scalar() Function
TenserFlow.js Tensors Creation Complete Reference
Tensorflow.js tf.Tensor class .buffer() Method
Tensorflow.js tf.Tensor class .bufferSync() Method
TensorFlow.js Tensors Classes Complete Reference
Tensorflow.js tf.booleanMaskAsync() Function
Tensorflow.js tf.concat() Function
TensorFlow.js Tensors Transformations Complete Reference
TensorFlow.js Slicing and Joining Complete Reference
Tensorflow.js tf.einsum() Function
Tensorflow.js tf.multinomial() Function
TensorFlow.js Tensor Random Complete Reference
Tensorflow.js tf.scalar() Function
Tensorflow.js tf.input() Function
Tensorflow.js tf.loadGraphModel() Function
Tensorflow.js tf.io.http() Function
TensorFlow.js Models Loading Complete Reference
Tensorflow.js tf.io.copyModel() Function
Tensorflow.js tf.io.listModels() Function
Tensorflow.js tf.io.moveModel() Function
TensorFlow.js Models Management Complete Reference
Tensorflow.js tf.GraphModel Class
Tensorflow.js tf.GraphModel class .save() Method
Tensorflow.js tf.GraphModel class .predict() Method
Tensorflow.js tf.GraphModel class .execute() Method
TensorFlow.js Models Classes Complete Reference
Tensorflow.js tf.scalar() Function
Tensorflow.js tf.layers.elu() Function
Tensorflow.js tf.layers.activation() Function
TensorFlow.js Layers Basic Complete Reference
Tensorflow.js tf.layers.conv1d() Function
TensorFlow.js Layers Convolutional Complete Reference
Tensorflow.js tf.layers.add() Function
TensorFlow.js Layers Merge Complete Reference
Tensorflow.js tf.layers.globalAveragePooling1d() Function
TensorFlow.js Layers Pooling Complete Reference
TensorFlow.js Layers Noise Complete Reference
Tensorflow.js tf.layers.bidirectional() Function
Tensorflow.js tf.layers.timeDistributed() Function
TensorFlow.js Layers Classes Complete Reference
Tensorflow.js tf.layers.zeroPadding2d() Function
Tensorflow.js tf.layers.masking() Function
Tensorflow.js tf.scalar() Function
TensorFlow.js Operations Arithmetic Complete Reference
TensorFlow.js Operations Basic Math Complete Reference
TensorFlow.js Operations Matrices Complete Reference
TensorFlow.js Operations Normalization Complete Reference
TensorFlow.js Operations Images Complete Reference
TensorFlow.js Operations Logical Complete Reference
TensorFlow.js Operations Evaluation Complete Reference
Tensorflow.js tf.cumsum() Function
TensorFlow.js Operations Slicing and Joining Complete Reference
TensorFlow.js Operations Spectral Complete Reference
Tensorflow.js tf.unsortedSegmentSum() Function
Tensorflow.js tf.movingAverage() Function
Tensorflow.js tf.dropout() Function
TensorFlow.js Operations Signal Complete Reference
Tensorflow.js tf.linalg.bandPart() Function
Tensorflow.js tf.linalg.gramSchmidt() Function
Tensorflow.js tf.linalg.qr() Function
TensorFlow.js Operations Sparse Complete Reference
Tensorflow.js tf.scalar() Function
Tensorflow.js tf.grad() Function
Tensorflow.js tf.grads() Function
Tensorflow.js tf.customGrad() Function
TensorFlow.js Training Gradients Complete ReferenceTensorflow.js TrainingTensorflow.js tf.train.momentum() FunctionTensorflow.js tf.train.adagrad() FunctionTensorFlow.js Training Optimizers Complete ReferenceTensorflow.js tf.losses.absoluteDifference() FunctionTensorflow.js tf.losses.computeWeightedLoss() FunctionTensorflow.js tf.losses.cosineDistance() FunctionTensorFlow.js Training Losses Complete ReferenceTensorflow.js tf.train.Optimizer ClassTensorflow.js tf.train.Optimizer class .minimize() MethodTensorFlow.js Training Classes Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js tf.time() FunctionTensorflow.js tf.nextFrame() FunctionTensorflow.js tf.profile() FunctionTensorFlow.js Performance Memory Complete ReferenceTensorflow.js PerformanceTensorflow.js tf.disposeVariables() FunctionTensorflow.js tf.enableDebugMode() FunctionTensorflow.js tf.enableProdMode() FunctionTensorflow.js tf.engine() FunctionTensorflow.js EnvironmentTensorFlow.js Environment Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js tf.metrics.binaryAccuracy() FunctionTensorflow.js tf.metrics.binaryCrossentropy() FunctionTensorflow.js tf.metrics.categoricalAccuracy() FunctionTensorflow.js tf.metrics.categoricalCrossentropy() FunctionTensorflow.js tf.metrics.cosineProximity() FunctionTensorflow.js ConstraintsTensorflow.js tf.metrics.meanSquaredError() FunctionTensorflow.js tf.metrics.precision() FunctionTensorflow.js tf.metrics.recall() FunctionTensorflow.js tf.metrics.sparseCategoricalAccuracy() FunctionTensorFlow.js Metrics Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js tf.initializers.Initializer ClassTensorflow.js tf.initializers.constant() MethodTensorflow.js tf.initializers.glorotNormal() FunctionTensorflow.js tf.initializers.glorotUniform() FunctionTensorflow.js tf.initializers.heNormal() FunctionTensorflow.js tf.initializers.heUniform() FunctionTensorflow.js InitializersTensorFlow.js Initializers Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js tf.regularizers.l1() FunctionTensorflow.js tf.regularizers.l1l2() FunctionTensorflow.js tf.regularizers.l2() FunctionTensorflow.js tf.scalar() FunctionTensorflow.js tf.data.csv() FunctionTensorflow.js tf.data.generator() FunctionTensorflow.js tf.data.microphone() FunctionTensorflow.js RegularizesTensorFlow.js Data Creation Complete ReferenceTensorflow.js tf.data.zip() FunctionTensorflow.js tf.data.Dataset class .batch() MethodTensorflow.js DataTensorFlow.js Data Classes Complete ReferencesTensorflow.js tf.scalar() FunctionTensorflow.js tf.util.assert() FunctionTensorflow.js tf.util.createShuffledIndices() FunctionTensorflow.js tf.decodeString() FunctionTensorflow.js tf.encodeString() FunctionTensorflow.js tf.fetch() FunctionTensorflow.js tf.util.flatten() FunctionTensorflow.js tf.util.now() FunctionTensorflow.js tf.util.shuffle() FunctionTensorflow.js tf.util.shuffleCombo() FunctionTensorflow.js UtilTensorflow.js tf.browser.fromPixels() FunctionTensorflow.js tf.browser.fromPixelsAsync() FunctionTensorflow.js tf.browser.toPixels() FunctionTensorFlow.js Browser Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js tf.backend() FunctionTensorflow.js tf.getBackend() FunctionTensorflow.js tf.ready() FunctionTensorflow.js tf.registerBackend() FunctionTensorflow.js tf.removeBackend() FunctionTensorflow.js tf.setBackend() FunctionTensorflow.js BrowserTensorflow.js tf.callbacks.earlyStopping() FunctionTensorflow.js BackendsTensorflow.js MetricsImprove Article

Save Article

Like Article

Tensorflow.js tf.scalar() FunctionLast Updated :
13 May, 2021Tensorflow.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 .scalar() function is used to create a scalar type of tensor means. A scaler is a zero-dimension array and is also called a rank-0 Tensor. A scalar is created using .scalar() function.Syntax:t.scalar( value, dataType )Parameters:value: The value of the scalar. The value can be a number, string, Uint8Array[ ], boolean.dataType [Optional]: The data type of the value. It can be an int32, float32, bool, complex64, or string.Return Value: It returns the Tensor Object.Creating a Scalar: In this example, we are creating a new scalar, means a tensor of only one value.Example 1:JavascriptJavascript// Importing the tensorflow.js libraryimport * as tf from "@tensorflow/tfjs" // Value of a scalarvar value = 12 // Creating the value of a scalarvar tens = tf.scalar(value) // Printing the scalartens.print();  Output:Tensor
    12Creating a scalar of a specific data type: In this example, we are creating a scalar of a specific data type. Note that the data type should only int32, float32, bool, complex64, or string.Example 2:JavascriptJavascript// Importing the tensorflow.js libraryimport * as tf from "@tensorflow/tfjs" // Creating a scalar using int valuevar int_tensor = tf.scalar(12, 'int32') int_tensor.print() // Creating a scalar using string valuevar str_tensor = tf.scalar("GFG", "string") str_tensor.print() // Creating a scalar using float valuevar float_tensor = tf.scalar(12.6, "float32") float_tensor.print(); // Creating a scalar using bool valuevar bool_tensor1 = tf.scalar(true, "bool") bool_tensor1.print() // Creating a scalar using bool(0 and 1) typevar bool_tensor2 = tf.scalar(0, "bool") bool_tensor2.print()Output: Tensor
    12
Tensor
    GFG
Tensor
    12.600000381469727
Tensor
    true
Tensor
    falseNote: You can also create a scalar using tf.tensor() function. Let’s see the example Creating a Scalar using tf.tensor() Function: Example 3:JavascriptJavascript// Importing the tensorflow.js libraryimport * as tf from "@tensorflow/tfjs" // Creating a scalar using int tf.tensor()var tens = tf.tensor(12, [], "int32") tens.print()Here we are providing the second parameter of function an empty array because we are creating a scalar and a scalar is rank-0 tensor. Output:Tensor
    12 My Personal Notes
arrow_drop_upSave

Like0PreviousTensorFlow.js Browser Complete ReferenceNext
Tensorflow.js tf.backend() FunctionRecommended ArticlesPage :How to get the function name from within that function using JavaScript ?30, May 19How to call a function that return another function in JavaScript ?24, Jul 19How to get the function name inside a function in PHP ?25, Sep 19How to Check a Function is a Generator Function or not using JavaScript ?26, Mar 20How to implement a function that enable another function after specified time using JavaScript ?10, Mar 21How to create a function that invokes the provided function with its arguments transformed in JavaScript?18, Jul 21How to create a function that invokes each provided function with the arguments it receives using JavaScript ?25, May 21How to create a function that invokes function with partials prepended arguments in JavaScript ?26, Jul 21Difference between ‘function declaration’ and ‘function expression' in JavaScript20, Sep 21Difference between Function.prototype.apply and Function.prototype.call16, Nov 21Explain the differences on the usage of foo between function foo() {} and var foo = function() {}02, Mar 22How does TypeScript support optional parameters in function as every parameter is optional for a function in JavaScript ?24, Mar 22What are the advantages of synchronous function over asynchronous function in Node.js ?28, Mar 22How to create a function that invokes function with partials appended to the arguments in JavaScript ?28, May 21PHP | imagecreatetruecolor() Function18, Sep 18p5.js | year() function07, Apr 19D3.js | d3.utcTuesdays() Function24, Jul 19PHP | ImagickDraw getTextAlignment() Function16, Dec 19PHP | Ds\Sequence last() Function24, Jan 19Function to escape regex patterns before applied in PHP31, Oct 19PHP | array_udiff_uassoc() Function11, Jul 18PHP | geoip_continent_code_by_name() Function01, Jul 18D3.js | d3.map.set() Function27, Jun 19D3.js easePolyOut Function03, Sep 20Article Contributed By :_saurabh_jaiswal@_saurabh_jaiswalVote for difficultyEasy
Normal
Medium
Hard
ExpertImproved By :parasmadan15bunnyram19Article Tags :TensorflowJavaScriptWeb TechnologiesImprove ArticleReport IssueWriting code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Load CommentsWhat's NewInterview Series- Prepare, Practice & UpskillView DetailsData Structures & Algorithms- Self Paced CourseView DetailsComplete Interview PreparationView DetailsMost popular in JavaScriptRemove elements from a JavaScript ArrayConvert a string to an integer in JavaScriptDifference between var, let and const keywords in JavaScriptDifferences between Functional Components and Class Components in ReactHow to calculate the number of days between two dates in javascript?Most visited in Web TechnologiesRemove elements from a JavaScript ArrayInstallation of Node.js on LinuxConvert a string to an integer in JavaScriptHow to fetch data from an API in ReactJS ?Top 10 Projects For Beginners To Practice HTML and CSS Skills
Tensorflow.js tf.train.momentum() Function
Tensorflow.js tf.train.adagrad() Function
TensorFlow.js Training Optimizers Complete Reference
Tensorflow.js tf.losses.absoluteDifference() Function
Tensorflow.js tf.losses.computeWeightedLoss() Function
Tensorflow.js tf.losses.cosineDistance() Function
TensorFlow.js Training Losses Complete Reference
Tensorflow.js tf.train.Optimizer Class
Tensorflow.js tf.train.Optimizer class .minimize() Method
TensorFlow.js Training Classes Complete Reference
Tensorflow.js tf.scalar() Function
Tensorflow.js tf.time() Function
Tensorflow.js tf.nextFrame() Function
Tensorflow.js tf.profile() Function
TensorFlow.js Performance Memory Complete Reference
Tensorflow.js tf.disposeVariables() Function
Tensorflow.js tf.enableDebugMode() Function
Tensorflow.js tf.enableProdMode() Function
Tensorflow.js tf.engine() FunctionTensorflow.js EnvironmentTensorFlow.js Environment Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js tf.metrics.binaryAccuracy() FunctionTensorflow.js tf.metrics.binaryCrossentropy() FunctionTensorflow.js tf.metrics.categoricalAccuracy() FunctionTensorflow.js tf.metrics.categoricalCrossentropy() FunctionTensorflow.js tf.metrics.cosineProximity() FunctionTensorflow.js ConstraintsTensorflow.js tf.metrics.meanSquaredError() FunctionTensorflow.js tf.metrics.precision() FunctionTensorflow.js tf.metrics.recall() FunctionTensorflow.js tf.metrics.sparseCategoricalAccuracy() FunctionTensorFlow.js Metrics Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js tf.initializers.Initializer ClassTensorflow.js tf.initializers.constant() MethodTensorflow.js tf.initializers.glorotNormal() FunctionTensorflow.js tf.initializers.glorotUniform() FunctionTensorflow.js tf.initializers.heNormal() FunctionTensorflow.js tf.initializers.heUniform() FunctionTensorflow.js InitializersTensorFlow.js Initializers Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js tf.regularizers.l1() FunctionTensorflow.js tf.regularizers.l1l2() FunctionTensorflow.js tf.regularizers.l2() FunctionTensorflow.js tf.scalar() FunctionTensorflow.js tf.data.csv() FunctionTensorflow.js tf.data.generator() FunctionTensorflow.js tf.data.microphone() FunctionTensorflow.js RegularizesTensorFlow.js Data Creation Complete ReferenceTensorflow.js tf.data.zip() FunctionTensorflow.js tf.data.Dataset class .batch() MethodTensorflow.js DataTensorFlow.js Data Classes Complete ReferencesTensorflow.js tf.scalar() FunctionTensorflow.js tf.util.assert() FunctionTensorflow.js tf.util.createShuffledIndices() FunctionTensorflow.js tf.decodeString() FunctionTensorflow.js tf.encodeString() FunctionTensorflow.js tf.fetch() FunctionTensorflow.js tf.util.flatten() FunctionTensorflow.js tf.util.now() FunctionTensorflow.js tf.util.shuffle() FunctionTensorflow.js tf.util.shuffleCombo() FunctionTensorflow.js UtilTensorflow.js tf.browser.fromPixels() FunctionTensorflow.js tf.browser.fromPixelsAsync() FunctionTensorflow.js tf.browser.toPixels() FunctionTensorFlow.js Browser Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js tf.backend() FunctionTensorflow.js tf.getBackend() FunctionTensorflow.js tf.ready() FunctionTensorflow.js tf.registerBackend() FunctionTensorflow.js tf.removeBackend() FunctionTensorflow.js tf.setBackend() FunctionTensorflow.js BrowserTensorflow.js tf.callbacks.earlyStopping() FunctionTensorflow.js BackendsTensorflow.js Metrics
TensorFlow.js Environment Complete Reference
Tensorflow.js tf.scalar() Function
Tensorflow.js tf.metrics.binaryAccuracy() Function
Tensorflow.js tf.metrics.binaryCrossentropy() Function
Tensorflow.js tf.metrics.categoricalAccuracy() Function
Tensorflow.js tf.metrics.categoricalCrossentropy() Function
Tensorflow.js tf.metrics.cosineProximity() Function
Tensorflow.js tf.metrics.meanSquaredError() Function
Tensorflow.js tf.metrics.precision() Function
Tensorflow.js tf.metrics.recall() Function
Tensorflow.js tf.metrics.sparseCategoricalAccuracy() Function
TensorFlow.js Metrics Complete Reference
Tensorflow.js tf.scalar() Function
Tensorflow.js tf.initializers.Initializer Class
Tensorflow.js tf.initializers.constant() Method
Tensorflow.js tf.initializers.glorotNormal() Function
Tensorflow.js tf.initializers.glorotUniform() Function
Tensorflow.js tf.initializers.heNormal() Function
Tensorflow.js tf.initializers.heUniform() Function
TensorFlow.js Initializers Complete Reference
Tensorflow.js tf.scalar() Function
Tensorflow.js tf.regularizers.l1() Function
Tensorflow.js tf.regularizers.l1l2() Function
Tensorflow.js tf.regularizers.l2() Function
Tensorflow.js tf.scalar() Function
Tensorflow.js tf.data.csv() Function
Tensorflow.js tf.data.generator() Function
Tensorflow.js tf.data.microphone() FunctionTensorflow.js RegularizesTensorFlow.js Data Creation Complete ReferenceTensorflow.js tf.data.zip() FunctionTensorflow.js tf.data.Dataset class .batch() MethodTensorflow.js DataTensorFlow.js Data Classes Complete ReferencesTensorflow.js tf.scalar() FunctionTensorflow.js tf.util.assert() FunctionTensorflow.js tf.util.createShuffledIndices() FunctionTensorflow.js tf.decodeString() FunctionTensorflow.js tf.encodeString() FunctionTensorflow.js tf.fetch() FunctionTensorflow.js tf.util.flatten() FunctionTensorflow.js tf.util.now() FunctionTensorflow.js tf.util.shuffle() FunctionTensorflow.js tf.util.shuffleCombo() FunctionTensorflow.js UtilTensorflow.js tf.browser.fromPixels() FunctionTensorflow.js tf.browser.fromPixelsAsync() FunctionTensorflow.js tf.browser.toPixels() FunctionTensorFlow.js Browser Complete ReferenceTensorflow.js tf.scalar() FunctionTensorflow.js tf.backend() FunctionTensorflow.js tf.getBackend() FunctionTensorflow.js tf.ready() FunctionTensorflow.js tf.registerBackend() FunctionTensorflow.js tf.removeBackend() FunctionTensorflow.js tf.setBackend() FunctionTensorflow.js BrowserTensorflow.js tf.callbacks.earlyStopping() FunctionTensorflow.js BackendsTensorflow.js Metrics
TensorFlow.js Data Creation Complete Reference
Tensorflow.js tf.data.zip() Function
Tensorflow.js tf.data.Dataset class .batch() Method
TensorFlow.js Data Classes Complete References
Tensorflow.js tf.scalar() Function
Tensorflow.js tf.util.assert() Function
Tensorflow.js tf.util.createShuffledIndices() Function
Tensorflow.js tf.decodeString() Function
Tensorflow.js tf.encodeString() Function
Tensorflow.js tf.fetch() Function
Tensorflow.js tf.util.flatten() Function
Tensorflow.js tf.util.now() Function
Tensorflow.js tf.util.shuffle() Function
Tensorflow.js tf.util.shuffleCombo() Function
Tensorflow.js tf.browser.fromPixels() Function
Tensorflow.js tf.browser.fromPixelsAsync() Function
Tensorflow.js tf.browser.toPixels() Function
TensorFlow.js Browser Complete Reference
Tensorflow.js tf.scalar() Function
Tensorflow.js tf.backend() Function
Tensorflow.js tf.getBackend() Function
Tensorflow.js tf.ready() Function
Tensorflow.js tf.registerBackend() Function
Tensorflow.js tf.removeBackend() Function
Tensorflow.js tf.setBackend() Function
Tensorflow.js tf.callbacks.earlyStopping() Function
Last Updated :
13 May, 2021
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 .scalar() function is used to create a scalar type of tensor means. A scaler is a zero-dimension array and is also called a rank-0 Tensor. A scalar is created using .scalar() function.
Syntax:
t.scalar( value, dataType )
Parameters:
value: The value of the scalar. The value can be a number, string, Uint8Array[ ], boolean.
dataType [Optional]: The data type of the value. It can be an int32, float32, bool, complex64, or string.
Return Value: It returns the Tensor Object.
Creating a Scalar: In this example, we are creating a new scalar, means a tensor of only one value.
Example 1:
Javascript
// Importing the tensorflow.js libraryimport * as tf from "@tensorflow/tfjs" // Value of a scalarvar value = 12 // Creating the value of a scalarvar tens = tf.scalar(value) // Printing the scalartens.print();
  
Output:
Tensor
    12
Creating a scalar of a specific data type: In this example, we are creating a scalar of a specific data type. Note that the data type should only int32, float32, bool, complex64, or string.
Example 2:
Javascript
// Importing the tensorflow.js libraryimport * as tf from "@tensorflow/tfjs" // Creating a scalar using int valuevar int_tensor = tf.scalar(12, 'int32') int_tensor.print() // Creating a scalar using string valuevar str_tensor = tf.scalar("GFG", "string") str_tensor.print() // Creating a scalar using float valuevar float_tensor = tf.scalar(12.6, "float32") float_tensor.print(); // Creating a scalar using bool valuevar bool_tensor1 = tf.scalar(true, "bool") bool_tensor1.print() // Creating a scalar using bool(0 and 1) typevar bool_tensor2 = tf.scalar(0, "bool") bool_tensor2.print()
Output: 
Tensor
    12
Tensor
    GFG
Tensor
    12.600000381469727
Tensor
    true
Tensor
    false
Note: You can also create a scalar using tf.tensor() function. Let’s see the example 
Creating a Scalar using tf.tensor() Function: 
Example 3:
Javascript
// Importing the tensorflow.js libraryimport * as tf from "@tensorflow/tfjs" // Creating a scalar using int tf.tensor()var tens = tf.tensor(12, [], "int32") tens.print()
Here we are providing the second parameter of function an empty array because we are creating a scalar and a scalar is rank-0 tensor. 
Output:
Tensor
    12
 
parasmadan15
bunnyram19
Tensorflow
JavaScript
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Remove elements from a JavaScript Array
Convert a string to an integer in JavaScript
Difference between var, let and const keywords in JavaScript
Differences between Functional Components and Class Components in React
How to calculate the number of days between two dates in javascript?
Remove elements from a JavaScript Array
Installation of Node.js on Linux
Convert a string to an integer in JavaScript
How to fetch data from an API in ReactJS ?
Top 10 Projects For Beginners To Practice HTML and CSS Skills