Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • TypeScript
  • Vue.js
  • D3.js
  • Collect.js
  • Underscore.js
  • Moment.js
  • Ember.js
  • Tensorflow.js
  • Fabric.js
  • JS Formatter
  • JavaScript
  • Web Technology
Open In App
Next Article:
Tensorflow.js tf.max() Function
Next article icon

Tensorflow.js tf.norm() Function

Last Updated : 12 May, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

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.norm() function is used compute the norm of matrices, vectors, and scalar. This function can also compute several other vector norms such as the 1-norm, the 2-norm or Euclidean, the inf-norm, and in general the p-norm for p > 0 and matrix norms.

Syntax:

tf.norm (x, ord?, axis?, keepDims?)

Parameters: This function accepts four parameters which is illustrated below:

  • x: The specifies the input array.
  • ord: This is optional. It specifies the order of the norm.
  • axis: This is optional. If axis is null, then the input is considered as a vector and a single vector norm is calculated over the whole set of values in the Tensor, i.e. norm(x, ord) is equivalent to norm(x.reshape([-1]), ord). Whereas if axis is an integer, then the input is inspected as a batch of vectors, and axis determines the x-axis over which vector norms is computed. If axis is a 2-tuple of integer it is considered as a batch of matrices and axis determines the axes in N-d array over which to compute a matrix norm.
  • keepDims: This is optional. If it is set to true, then the norm have the same dimension as the input.

Return Value: It returns tf.tensor.

Below are the examples that illustrates the use of tf.norm() function.

Example 1:

Javascript

// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Initializing a tensor of some elements
let Norm = tf.tensor1d([15, 14, 23, 52]);
  
// Calling the .norm() function over
// the above tensor as its parameter
// and printing the result.
Norm.norm().print();
                      
                       

Output:

Tensor      60.44832992553711

Example 2:

Javascript

// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Initializing a tensor of some elements
let Norm = tf.tensor1d([5, 4, 3, 2]);
  
// Calling the .norm() function over
// the above tensor as its parameter
// and printing the result.
tf.norm(Norm).print();
                      
                       


Output:

Tensor      7.348469257354736
Reference: https://js.tensorflow.org/api/latest/#norm


Next Article
Tensorflow.js tf.max() Function

T

thacker_shahid
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • Tensorflow.js

Similar Reads

  • Tensorflow.js tf.max() 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.max() function is used to calculate the maximum value from the specified Tensor across its dimension. It reduces the given inpu
    2 min read
  • 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.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
  • Tensorflow.js tf.sum() 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.sum() function is used to calculate sum of the elements of a specified Tensor across its dimension. It reduces the given input
    2 min read
  • Tensorflow.js tf.sin() Function
    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 .sin() function is used to find the sin of the stated tensor input, and it is done element wise. Syntax :   t
    2 min read
  • Tensorflow.js tf.tan() Function
    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 .tan() function is used to find the tangent of the stated tensor input and is done element wise. Syntax: tf.t
    2 min read
  • Tensorflow.js tf.log() Function
    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 eleme
    1 min read
  • Tensorflow.js tf.mod() 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.mod() function returns element-wise remainder of division. Operation: floor(x / y) * y + mod(x, y) = x. Note: It supports broad
    2 min read
  • Tensorflow.js tf.pow() 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.pow() function is used to compute the power of one specified tensor to another. It supports broadcasting. Syntax: tf.power(base
    2 min read
  • Tensorflow.js tf.tensor2d() 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 .tensor2d() function is used to create a new 2-dimensional tensor with the parameter namely value, shape, and datatype. Syntax: tf
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All 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
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences