How to find max and min of a torch tensor

This recipe helps you find max and min of a torch tensor

Recipe Objective

How to find max and min of a torch tensor?

This is achieved by using .min and .max function, first take a sample tensor then apply these functions on it to fond the minimum and maximum value of a tensor.

Step 1 - Import library

import torch

Step 2 - Take Sample tensor

torch_ten = torch.randn(10)
print("This is a Sample torch tensor:", torch_ten)

This is a Sample torch tensor: tensor([-1.4027, -1.6721,  0.8212, -0.5046,  0.5234,  1.5095, -2.3647,  0.3108,
         0.4532,  2.3433])

Step 3 - Find minimum and maximum

print("This is minimum value of Sample tensor:",torch.min(torch_ten))
print("This is maximum value of Sample tensor:",torch.max(torch_ten))

This is minimum value of Sample tensor: tensor(-2.3647)
This is maximum value of Sample tensor: tensor(2.3433)

{"mode":"full","isActive":false}

What Users are saying..

profile image

Ray han

Tech Leader | Stanford / Yale University
linkedin profile url

I think that they are fantastic. I attended Yale and Stanford and have worked at Honeywell,Oracle, and Arthur Andersen(Accenture) in the US. I have taken Big Data and Hadoop,NoSQL, Spark, Hadoop... Read More

Relevant Projects

Personalized Medicine: Redefining Cancer Treatment
In this Personalized Medicine Machine Learning Project you will learn to classify genetic mutations on the basis of medical literature into 9 classes.

Langchain Project for Customer Support App in Python
In this LLM Project, you will learn how to enhance customer support interactions through Large Language Models (LLMs), enabling intelligent, context-aware responses. This Langchain project aims to seamlessly integrate LLM technology with databases, PDF knowledge bases, and audio processing agents to create a comprehensive customer support application.

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

Time Series Project to Build a Multiple Linear Regression Model
Learn to build a Multiple linear regression model in Python on Time Series Data

BigMart Sales Prediction ML Project in Python
The goal of the BigMart Sales Prediction ML project is to build and evaluate different predictive models and determine the sales of each product at a store.

Learn to Build a Polynomial Regression Model from Scratch
In this Machine Learning Regression project, you will learn to build a polynomial regression model to predict points scored by the sports team.

ML Model Deployment on AWS for Customer Churn Prediction
MLOps Project-Deploy Machine Learning Model to Production Python on AWS for Customer Churn Prediction

Predictive Analytics Project for Working Capital Optimization
In this Predictive Analytics Project, you will build a model to accurately forecast the timing of customer and supplier payments for optimizing working capital.

Avocado Machine Learning Project Python for Price Prediction
In this ML Project, you will use the Avocado dataset to build a machine learning model to predict the average price of avocado which is continuous in nature based on region and varieties of avocado.

Time Series Forecasting with LSTM Neural Network Python
Deep Learning Project- Learn to apply deep learning paradigm to forecast univariate time series data.