
Quick Contact
Python Tutorial
- What is Python?
- How to Install Python?
- Python Variables and Operators
- Python Loops
- Python Functions
- Python Files
- Python Errors and Exceptions
- Python Packages
- Python Classes and Objects
- Python Strings
- PostgreSQL Data Types
- Python Generators and Decorators
- Python Dictionary
- Python Date and Time
- Python List and Tuples
- Python Multithreading and Synchronization
- Python Modules
- What is Python bytecode?
- Python Regular Expressions
Python Panda Tutorial
- Python Pandas Tutorial
- Python Pandas Features
- Advantages and Disadvantages of Python Pandas
- Pandas Library In Python
- Pandas Series To Frame
- Python Dataframeaggregate and Assign
- Pandas Dataframe Describe
- Pandas Dataframe Mean
- Pandas Hist
- Pandas Dataframe Sum
- How to convert Pandas DataFrame to Numpy array
Python Selenium
- Selenium Basics
- Selenium with Python Introduction and Installation
- Navigating links using get method Selenium Python
- Locating Single Elements in Selenium Python
- Locating Multiple elements in Selenium Python
Python Flask Tutorial
Python Django
- How to Install Django and Set Up a Virtual Environment in 6 Steps
- Django MTV Architecture
- Django Models
- Django Views
- Django Templates
- Django Template Language
- Django Project Layout
- Django Admin Interface
- Django Database
- Django URLs and URLConf
- Django Redirects
- Django Cookies and Cookies Handling
- Django Caching
- Types of Caching in Django
- Django Sessions
- Django Forms Handling & Validation
- Django Exceptions & Error-handling
- Django Forms Validation
- Django Redirects
- Django Admin Interface
- Django Bootstrap
- Ajax in Django
- Django Migrations and Database Connectivity
- Django Web Hosting and IDE
- Django Admin Customization
- What is CRUD?
- Django ORM
- Django Request-Response Cycle
- Django ORM
- Making a basic_api with DRF
- Django Logging
- Django Applications
- Difference between Flask vs Django
- Difference between Django vs PHP
Numpy
- Numpy Introduction
- NumPy– Environment Setup
- NumPy - Data Types
- NumPy–Functions
- NumPy Histogram
- numPy.where
- numpy.sort
- NumPyfloor
- Matrix in NumPy
- NumPy Arrays
- NumPy Array Functions
- Matrix Multiplication in NumPy
- NumPy Matrix Transpose
- NumPy Array Append
- NumPy empty array
- NumPy Linear Algebra
- numpy.diff()
- numpy.unique()
- numpy.dot()
- numpy.mean()
- Numpy.argsort()
- numpy.pad()
- NumPyvstack
- NumPy sum
- NumPy Normal Distribution
- NumPylogspace()
- NumPy correlation
- Why we learn and use Numpy?
Tensorflow
- Introduction To Tensorflow
- INTRODUCTION TO DEEP LEARNING
- EXPLAIN NEURAL NETWORK?
- CONVOLUTIONAL AND RECURRENT NEURAL NETWORK
- INTRODUCTION TO TENSORFLOW
- INSTALLATION OF TENSORFLOW
- TENSORBOARD VISUALIZATION
- Linear regression in tensorflow
- Word Embedding
- Difference between CNN And RNN
- Explain Keras
- Program elements in tensorflow
- Recurrent Neural Network
- Tensorflow Object Detection
- EXPLAIN MULTILAYER PERCEPTRON
- GRADIENT DESCENT OPTIMIZATION
Interview Questions & Answers
NumPy sum
In this article, NumPy sum in Python is defined as a Python library which is specially designed for working on the multi-dimensional array and matrices and NumPy sum() is a function provided by the NumPy Python library that is mainly used to calculate the total sum of the elements present in the given array or the total sum of elements in each row and sum of elements in each column if it in the given matrices or multi-dimensional array and the value returned by the sum() function results in the form of an array object.
Working of NumPysum() Function in Python with Examples
In this article, we will see the NumPy Python library’s function sum(). In Python, the NumPy sum() function is used for computing the summation of the total number of items present in the given array which means the elements are taken within the NumPy array as an array object and sums up the items of a given array.
Syntax and parameters taken by sum() function of NumPy in Python:
Numpy.sum(in_array, axis, dtype, out, keepdims, initial)
Parameters:
-
in_array:
This parameter is to specify the array name of the input array so that the elements are used to calculate the sum.
-
axis:
This value can be either none or int or tuple of ints, where this parameter is used for defining the axis for which the sum needs to be computed and the default value specified is none where it will compute the sum of all the elements of the given array.
-
dtype:
This parameter is used for defining the type of accumulator and to specify the returned data type of the output.
-
out:
This parameter is used to specify another extra array to store the result or output and the size of this array must be the same as the size of the input array.
-
keepdims:
This specifies the Boolean value where it is set to true where if the axes are reduced are left in the output result having the dimensions as size one.
-
initial:
It is used to specify the starting or initial value for calculating the sum.
Example #1
Code:
import numpy as np print("Program to demonstrate numpy sum() function: ") print("\n") in_arr = np.array([0,1,3,5,34,10]) print("The given array is as follows:") print(in_arr) print("\n") print("The sum of the given array is:") sum_res = np.sum(in_arr) print(sum_res)
In the above program, we can see we have imported NumPy module and then we have created an array using NumPy object np and then using sum() function and passing this given array as input array to the function and the returns the sum of the element values in the given input array. Usually, the sum of the empty array is a neutral value that is 0. In the above we saw how to add elements of the one-dimensional array.
Example #2
Let us see how to add the elements of the two-dimensional array in the below example along with different other parameters of the sum() function such as axis, data type.
Code:
import numpy as np print("Program to demonstrate numpy sum() function for 2D array: ") print("\n") in_arr = np.array( [[8,1,9], [6,4,1]]) print("The given input 2-D array is as follows:") print(in_arr) print("\n") res_arr_1 = np.sum(in_arr, axis=1, dtype=float) print("Sum of elements at axis 1 row wise with the specified data type is") print(res_arr_1) print("\n") res_arr_2 = np.sum(in_arr, axis=0, dtype=int) print("Sum of elements at axis 0 column wise with the specified data type is") print(res_arr_2) print("\n") res = np.sum(in_arr, axis=1, keepdims = True) print("Keeping the dimensional of the output array same as input array") print(res) print("\n") print("Sum of the total elements in the 2-D array is as follows:") tot_res = np.sum(in_arr) print(tot_res)