What does the function reduce sum do in tensorflow

This recipe explains what does the function reduce sum do in tensorflow

Recipe Objective

What does the function reduce_sum do?

This function will compute the sum of the elements across the dimensions of a tensor. This is achived by using "math.reduce_sum" available in tensorflow, it will reduces the input_tensor along the dimensions pf given in axis. The Rank of the tensor id reduced to 1 for each of the entries in the axis unless the "keepdims" is true. The reduced dimensions are retained with length 1 if the "keepdims" is true.

Complete Guide to Tensorflow for Deep Learning with Python for Free

Step 1 - Import library

import tensorflow as tf

Step 2 - Take Sample data

Sample_value = tf.constant([[2,2,3],[3,3,4]]) print("This is a Sample value:",Sample_value)

This is a Sample value: tf.Tensor(
[[2 2 3]
 [3 3 4]], shape=(2, 3), dtype=int32)

Step 3 - Print Results

result_reduced_sum = tf.math.reduce_sum(Sample_value) print("This is result of reduced_sum value:",result_reduced_sum)

This is result of reduced_sum value: tf.Tensor(17, shape=(), dtype=int32)

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

What Users are saying..

profile image

Anand Kumpatla

Sr Data Scientist @ Doubleslash Software Solutions Pvt Ltd
linkedin profile url

ProjectPro is a unique platform and helps many people in the industry to solve real-life problems with a step-by-step walkthrough of projects. A platform with some fantastic resources to gain... Read More

Relevant Projects

Build a Customer Churn Prediction Model using Decision Trees
Develop a customer churn prediction model using decision tree machine learning algorithms and data science on streaming service data.

Build an AI Chatbot from Scratch using Keras Sequential Model
In this NLP Project, you will learn how to build an AI Chatbot from Scratch using Keras Sequential Model.

Detectron2 Object Detection and Segmentation Example Python
Object Detection using Detectron2 - Build a Dectectron2 model to detect the zones and inhibitions in antibiogram images.

Build Time Series Models for Gaussian Processes in Python
Time Series Project - A hands-on approach to Gaussian Processes for Time Series Modelling in Python

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.

Learn Object Tracking (SOT, MOT) using OpenCV and Python
Get Started with Object Tracking using OpenCV and Python - Learn to implement Multiple Instance Learning Tracker (MIL) algorithm, Generic Object Tracking Using Regression Networks Tracker (GOTURN) algorithm, Kernelized Correlation Filters Tracker (KCF) algorithm, Tracking, Learning, Detection Tracker (TLD) algorithm for single and multiple object tracking from various video clips.

Classification Projects on Machine Learning for Beginners - 2
Learn to implement various ensemble techniques to predict license status for a given business.

BERT Text Classification using DistilBERT and ALBERT Models
This Project Explains how to perform Text Classification using ALBERT and DistilBERT

Build Regression Models in Python for House Price Prediction
In this Machine Learning Regression project, you will build and evaluate various regression models in Python for house price prediction.

End-to-End ML Model Monitoring using Airflow and Docker
In this MLOps Project, you will learn to build an end to end pipeline to monitor any changes in the predictive power of model or degradation of data.