EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials PyTorch Tutorial PyTorch norm
Secondary Sidebar
PyTorch Tutorial
  • PyTorch
    • PyTorch Image Classification
    • PyTorch Random
    • PyTorch Variable
    • PyTorch Activation Function
    • Python Formatted String
    • PyTorch GPU
    • PyTorch CUDA
    • PyTorch DataLoader
    • PyTorch LSTM
    • PyTorch Pad
    • PyTorch OpenCL
    • PyTorch Lightning
    • PyTorch SoftMax
    • PyTorch Flatten
    • PyTorch gan
    • PyTorch max
    • PyTorch pip
    • PyTorch Parameter
    • PyTorch Load Model
    • PyTorch Distributed
    • PyTorch BERT
    • PyTorch interpolate
    • PyTorch JIT
    • PyTorch expand
    • PyTorch AMD
    • PyTorch GRU
    • PyTorch rnn
    • PyTorch permute
    • PyTorch argmax
    • PyTorch SGD
    • PyTorch nn
    • PyTorch One Hot Encoding
    • PyTorch Tensors
    • What is PyTorch?
    • PyTorch MSELoss()
    • PyTorch NLLLOSS
    • PyTorch MaxPool2d
    • PyTorch Pretrained Models
    • PyTorch Squeeze
    • PyTorch Reinforcement Learning
    • PyTorch zero_grad
    • PyTorch norm
    • PyTorch VAE
    • PyTorch Early Stopping
    • PyTorch requires_grad
    • PyTorch MNIST
    • PyTorch Conv2d
    • Dataset Pytorch
    • PyTorch tanh
    • PyTorch bmm
    • PyTorch profiler
    • PyTorch unsqueeze
    • PyTorch adam
    • PyTorch backward
    • PyTorch concatenate
    • PyTorch Embedding
    • PyTorch Tensor to NumPy
    • PyTorch Normalize
    • PyTorch ReLU
    • PyTorch Autograd
    • PyTorch Transpose
    • PyTorch Object Detection
    • PyTorch Autoencoder
    • PyTorch Loss
    • PyTorch repeat
    • PyTorch gather
    • PyTorch sequential
    • PyTorch U-NET
    • PyTorch Sigmoid
    • PyTorch Neural Network
    • PyTorch Quantization
    • PyTorch Ignite
    • PyTorch Versions
    • PyTorch TensorBoard
    • PyTorch Dropout
    • PyTorch Model
    • PyTorch optimizer
    • PyTorch ResNet
    • PyTorch CNN
    • PyTorch Detach
    • Single Layer Perceptron
    • PyTorch vs Keras
    • torch.nn Module

PyTorch norm

PyTorch norm

Definition of PyTorch norm

PyTorch provides the different types of functionality to the user, in which that norm is one the functionality that is provided by the PyTorch. Basically in deep learning sometimes we need to fetch the matrix or vector from the input tensor. At that time we can use the norm function to implement the deep learning algorithm efficiently as per our requirement. torch. norm is deplored and might be taken out in a future PyTorch discharge. Its documentation and conduct might be wrong, and it is not generally effectively kept up with. On the other side, we have torch.linalg.norm to get the required predicted outcomes as per requirement.

What is PyTorch norm?

First, try to understand what vector norm is which is as follows.

  • Vector Norm

Working out the size or length of a vector is regularly required either straightforwardly or as a component of a more extensive vector or vector-network activity. The length of the vector is alluded to as the vector standard or the vector’s size. The length of a vector is a non-negative number that portrays the degree of the vector in space and is once in a while alluded to as the vector’s extent or the standard.

The length of the vector is consistently a positive number, aside from a vector of every one of the zero qualities. It is determined utilizing some action that sums up the distance of the vector from the beginning of the vector space. For instance, the beginning of a vector space for a vector with 4 components is (0, 0, 0, 0).

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Documentations are utilized to address the vector standard in more extensive estimations and the kind of vector standard computation quite often has its own novel documentation.

  • Vector L1 Norm

The length of a vector can be determined utilizing the L1 standard, where the 1 is a superscript of the L, for example, L^1.
The documentation for the L1 standard of a vector is v 1, where 1 is an addendum. All things considered, this length is of the time called the taxi standard or the Manhattan standard.

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,560 ratings)
  • Vector L2 Norm

We can determine the length of the vector by using L2 and 2 is the superscript of L. The documentation for the L2 standard of a vector is v 2 where 2 is an addendum.

  • Vector Max Norm

The length of a vector can be determined utilizing the greatest standard, additionally called the max standard. Max standard of a vector is alluded to as L^inf where inf is a superscript and can be addressed with the boundlessness image. The documentation for the max standard is x inf, where inf is an addendum.

How to Use PyTorch norm?

Now let’s see how we can use the PyTorch norm as follows.

Syntax:

torch.norm(specified input, pr = value, dimension = none, kdimension = false, result = none, datatype = none)

Explanation

In the above syntax, we use the norm () function with different parameters as shown.

  • Specified input: The information tensor. Its information type should be either a drifting point or complex sort. For complex data sources, the standard is determined utilizing the outright worth of every component. On the off chance that the information neither is perplexing and neither data type nor out is determined, the outcome’s information type will be the comparing drifting point type (for example float assuming the info is complex float).
  • Pr: This is an optional part of the syntax. It consists of the following norms such as fro, nuc, and number.
  • Dimension: It determines which aspect or aspects of contribution to work out the standard across. Assuming that faint is none, the standard will be determined across all elements of info. Assuming the standard sort shown by p doesn’t uphold the predefined number of aspects, a mistake will happen.
  • Kdimension: it is a Boolean and optional part of this syntax, it shows whether tensor is retained or not and the default value is false.
    Result: This is used for the output tensor.
  • Datatype: the ideal information kind of brought tensor back. Whenever indicated, the information tensor is cast to data type while playing out the activity. Default: None.

PyTorch norm function

Now let’s see the different functions of the norm as follows.

Standard of a vector is “the size or length of a vector is a non-negative number that depicts the degree of the vector in space, and is once in a while alluded to as the vector’s extent or the standard”
1-Norm is “the amount of the outright vector esteems, where the outright worth of a scalar uses the documentation |a1|. As a result, the standard is a computation of the Manhattan distance from the beginning of the vector space.”
2-Norm is also called a distance vector.

PyTorch norm Examples

Now let’s see different examples of the norm for better understanding as follows.

import torch
A = torch.arange(12, dtype= torch.float) - 3
B = A.reshape((3, 4))
output = torch.norm(A)
print(output)

Explanation

In the above example we try to implement the norm () function as shown, here first we import the torch package after that we use the arange () and reshape () function for the norm as shown and finally we print the result. The final output of the above implement we illustrated by using the following screenshot as follows.

3

Now let’s see another example of the norm as follows.

import torch
A = torch.arange(12, dtype= torch.float) - 3
B = A.reshape((3, 4))
output_a = torch.norm(A)
print(output_a)
output_b = torch.norm(B)
print(output_b)
output_1 = torch.norm(A, float('inf'))
print(output_1)
output_2 = torch.norm(B, float('inf'))
print(output_2)

Explanation

In the above example, we additionally add a float with inf as shown. The final output of the above implement we illustrated by using the following screenshot as follows.

4

Conclusion

We hope from this article you learn more about the PyTorch norm. From the above article, we have taken in the essential idea of the PyTorch norm and we also see the representation and example of the PyTorch norm. From this article, we learned how and when we use the PyTorch norm.

Recommended Articles

This is a guide to PyTorch norm. Here we discuss the Introduction to PyTorch norm, Working of PyTorch function along with examples and code respectively. You may also have a look at the following articles to learn more –

  1. PyTorch Conv2d
  2. What is PyTorch?
  3. PyTorch vs Keras
  4. Dataset Pytorch
Popular Course in this category
Machine Learning Training (20 Courses, 29+ Projects)
  19 Online Courses |  29 Hands-on Projects |  178+ Hours |  Verifiable Certificate of Completion
4.7
Price

View Course
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more