What is the use of torch argmax and torch argmin functions

This recipe explains what is the use of torch argmax and torch argmin functions

Recipe Objective

What is the use of torch.argmax and torch.argmin functions?

The function torch.argmax will return the indices of maximum value of all the elements in the input tensor. Whereas torch.argmin will return minimum value of all the elements in the input tensor.

Step 1 - Import library

import torch

Step 2 - Take Sample data

Sample = torch.randn(3,3)
Sample

tensor([[-0.3292, -0.3550, -0.5400],
        [-0.3573,  1.9466, -0.5090],
        [-0.1529, -1.1344,  0.3330]])

Step 3 - Perform argmax and argmin

max = torch.argmax(Sample)
min = torch.argmin(Sample)
print("This is the maximum value in the input tensor:",max)
print("This is the minimum value in the input tensor:",min)

This is the maximum value in the input tensor: tensor(4)
This is the minimum value in the input tensor: tensor(7)

What Users are saying..

profile image

Gautam Vermani

Data Consultant at Confidential
linkedin profile url

Having worked in the field of Data Science, I wanted to explore how I can implement projects in other domains, So I thought of connecting with ProjectPro. A project that helped me absorb this topic... Read More

Relevant Projects

Linear Regression Model Project in Python for Beginners Part 2
Machine Learning Linear Regression Project for Beginners in Python to Build a Multiple Linear Regression Model on Soccer Player Dataset.

Expedia Hotel Recommendations Data Science Project
In this data science project, you will contextualize customer data and predict the likelihood a customer will stay at 100 different hotel groups.

Build a Multi Touch Attribution Machine Learning Model in Python
Identifying the ROI on marketing campaigns is an essential KPI for any business. In this ML project, you will learn to build a Multi Touch Attribution Model in Python to identify the ROI of various marketing efforts and their impact on conversions or sales..

Build Multi Class Text Classification Models with RNN and LSTM
In this Deep Learning Project, you will use the customer complaints data about consumer financial products to build multi-class text classification models using RNN and LSTM.

Learn to Build a Siamese Neural Network for Image Similarity
In this Deep Learning Project, you will learn how to build a siamese neural network with Keras and Tensorflow for Image Similarity.

Learn How to Build a Linear Regression Model in PyTorch
In this Machine Learning Project, you will learn how to build a simple linear regression model in PyTorch to predict the number of days subscribed.

Build Real Estate Price Prediction Model with NLP and FastAPI
In this Real Estate Price Prediction Project, you will learn to build a real estate price prediction machine learning model and deploy it on Heroku using FastAPI Framework.

Model Deployment on GCP using Streamlit for Resume Parsing
Perform model deployment on GCP for resume parsing model using Streamlit App.

Build CNN for Image Colorization using Deep Transfer Learning
Image Processing Project -Train a model for colorization to make grayscale images colorful using convolutional autoencoders.

Build Customer Propensity to Purchase Model in Python
In this machine learning project, you will learn to build a machine learning model to estimate customer propensity to purchase.