Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Numpy exercise
  • pandas
  • Matplotlib
  • Data visulisation
  • EDA
  • Machin Learning
  • Deep Learning
  • NLP
  • Data science
  • ML Tutorial
  • Computer Vision
  • ML project
Open In App
Next Article:
NumPy - Arithmetic Operations
Next article icon

NumPy - Arithmetic Operations

Last Updated : 15 May, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Arithmetic operations are used for numerical computation and we can perform them on arrays using NumPy. With NumPy we can quickly add, subtract, multiply, divide and get power of elements in an array. NumPy performs these operations even with large amounts of data. In this article, we’ll see at the basic arithmetic functions in NumPy and show how to use them for simple calculations.

1. Addition of Arrays

Addition is an arithmetic operation where the corresponding elements of two arrays are added together. In NumPy the addition of two arrays is done using the np.add() function.

Python
import numpy as np  a = np.array([5, 72, 13, 100]) b = np.array([2, 5, 10, 30])  add_ans = np.add(a, b) print(add_ans) 

Output:

[ 7 77 23 130]

2. Subtraction of Arrays

We can subtract two arrays element-wise using the np.subtract() function. This function subtracts each element of the second array from the corresponding element in the first array.

Python
import numpy as np  a = np.array([5, 72, 13, 100]) b = np.array([2, 5, 10, 30])  sub_ans = np.subtract(a, b) print(sub_ans) 

Output:

[ 3 67 3 70]

3. Multiplication of Arrays

Multiplication in NumPy can be done element-wise using the np.multiply() function. This multiplies corresponding elements of two arrays.

Python
import numpy as np  a = np.array([5, 72, 13, 100]) b = np.array([2, 5, 10, 30])  mul_ans = np.multiply(a, b) print(mul_ans) 

Output:

[ 10 360 130 3000]

4. Division of Arrays

Division is another important operation that is performed element-wise using the np.divide() function. This divides each element of the first array by the corresponding element in the second array.

Python
import numpy as np  a = np.array([5, 72, 13, 100]) b = np.array([2, 5, 10, 30])  div_ans = np.divide(a, b) print(div_ans) 

Output:

[ 2.5 14.4 1.3 3.33333333]

5. Exponentiation (Power)

It allows us to raise each element in an array to a specified power. In NumPy, this can be done using the np.power() function.

Python
import numpy as np   a = np.array([5, 72, 13, 100]) b = np.array([2, 5, 10, 30])  pow_ans = np.power(a, b) print(pow_ans) 

Output:

[25 1934917632 137858491849 1152921504606846976]

6. Modulus Operation

It finds the remainder when one number is divided by another. In NumPy, you can use the np.mod() function to calculate the modulus element-wise between two arrays.

Python
import numpy as np   a = np.array([5, 72, 13, 100]) b = np.array([2, 5, 10, 30])  mod_ans = np.mod(a, b) print(mod_ans) 

Output:

[ 1 2 3 10]

With these basic arithmetic functions in NumPy we can efficiently perform calculations on arrays.


Next Article
NumPy - Arithmetic Operations

A

apurva__007
Improve
Article Tags :
  • Python
  • Numpy
  • Python-numpy
  • Python numpy-Mathematical Function
Practice Tags :
  • python

Similar Reads

    Arithmetic Operations
    Arithmetic Operations are the basic mathematical operations—Addition, Subtraction, Multiplication, and Division—used for calculations. These operations form the foundation of mathematics and are essential in daily life, such as sharing items, calculating bills, solving time and work problems, and in
    9 min read
    Arithmetic Operators in LISP
    Arithmetic operators are used to perform mathematical operations like addition, subtraction, multiplication, and division. There are 7 arithmetic operators in LISP that are listed in the below table: OperatorSyntaxDescriptionAddition Operator(+)+ num1 num2Add the two numbersSubtraction Operator(-)-
    2 min read
    JavaScript Arithmetic Operators
    JavaScript Arithmetic Operators are the operator that operate upon the numerical values and return a numerical value. Addition (+) OperatorThe addition operator takes two numerical operands and gives their numerical sum. It also concatenates two strings or numbers.JavaScript// Number + Number =>
    6 min read
    Arithmetic Operators in Solidity
    Arithmetic operators are used to perform arithmetic or mathematical operations. Solidity has the following types of arithmetic operators: Addition: The addition operator takes two operands and results in a sum of these operands. It is denoted by +.Subtraction: The subtraction operator takes two oper
    2 min read
    Python Arithmetic Operators
    Python operators are fundamental for performing mathematical calculations. Arithmetic operators are symbols used to perform mathematical operations on numerical values. Arithmetic operators include addition (+), subtraction (-), multiplication (*), division (/), and modulus (%). OperatorDescriptionS
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences