Skip to content
geeksforgeeks
  • 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
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • 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.mod() in Python
Next article icon

numpy.multiply() in Python

Last Updated : 17 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

The numpy.multiply() is a numpy function in Python which is used to find element-wise multiplication of two arrays or scalar (single value). It returns the product of two input array element by element.

Syntax:

numpy.multiply(arr1, arr2, out=None, where=True, casting=’same_kind’, order=’K’, dtype=None, subok=True)

Parameters:

  • arr1 (array_like or scalar): First input array.
  • arr2 (array_like or scalar): Second input array.
  • dtype (optional): Desired type of the returned array. By default dtype of arr1 is used.
  • out (optional, ndarray): A location where result is stored. If not provided a new array is created.
  • where (optional, array_like): A condition to find where multiplication should happen. If True multiplication occurs at that position and if False value in output remains unchanged.

Return: ndarray (Element-wise product of arr1 and arr2).

Example 1: Multiplying a Scalar with a scalar

  • out_num = geek.multiply(in_num1, in_num2): Multiplies in_num1andin_num2 using multiply and stores the result in out_num.
Python
import numpy as geek in_num1 = 4 in_num2 = 6 print ("1st Input  number : ", in_num1) print ("2nd Input  number : ", in_num2) out_num = geek.multiply(in_num1, in_num2)  print ("output number : ", out_num)  

Output:

multiply-ex1

Multiplying a Scalar with a scalar

Example 2: Multiplying a Scalar with an Array

When one of the inputs is a scalar it is multiplied with each element of the array. This operation is commonly used for scaling or adjusting values in an array. Here Scalar value 5 is multiplied with each element 1,2,3.

Python
import numpy as geek in_arr = geek.array([1, 2, 3]) scalar_value = 5  result_arr = geek.multiply(in_arr, scalar_value) print(result_arr) 

Output:

[ 5 10 15]

Example 3: Element-wise Multiplication of Arrays

When both inputs are arrays of the same shape numpy.multiply() multiplies corresponding elements together. This operation is performed element by element.

Python
import numpy as geek in_arr1 = geek.array([[2, -7, 5], [-6, 2, 0]]) in_arr2 = geek.array([[0, -7, 8], [5, -2, 9]]) print ("1st Input array : ", in_arr1) print ("2nd Input array : ", in_arr2) out_arr = geek.multiply(in_arr1, in_arr2)  print ("Resultant output array: ", out_arr)  

Output

multiple-ex-3

Multiplying a Scalar with an Array

In above example corresponding elements from in_arr1 and in_arr2 are multiplied:

  • 2 * 0 = 0
  • -7 * -7 = 49
  • 5 * 8 = 40
  • -6 * 5 = -30
  • 2 * -2 = -4
  • 0 * 9 = 0

Example 4: Multiplying Arrays with Different Shapes (Broadcasting)

numpy.multiply() supports broadcasting which means it can multiply arrays with different shapes as long as they are compatible for broadcasting rules.

Python
import numpy as geek in_arr1 = geek.array([1, 2, 3]) in_arr2 = geek.array([[4], [5], [6]])  result_arr = geek.multiply(in_arr1, in_arr2) print(result_arr) 

Output:

multiply-ex-4

Arrays with Different Shapes

In this example in_arr1 is broadcasted to match the shape of in_arr2 for element-wise multiplication.

To understand broadcasting you can refer to this article: NumPy Array Broadcasting

Example 5: Using out Parameter

We can specify an output array where result of the multiplication will be stored. This avoids creating a new array and can help save memory when working with large datasets.

Python
import numpy as geek in_arr1 = geek.array([1, 2, 3]) in_arr2 = geek.array([4, 5, 6]) output_arr = geek.empty_like(in_arr1) geek.multiply(in_arr1, in_arr2, out=output_arr) print(output_arr) 

Output:

[ 4 10 18]

Result of element-wise multiplication is stored in output_arr instead of creating a new array. By mastering numpy.multiply() we can efficiently handle element-wise multiplication across arrays and scalars.



Next Article
numpy.mod() in Python
author
jana_sayantan
Improve
Article Tags :
  • Python
  • Python numpy-Mathematical Function
  • Python-numpy
Practice Tags :
  • python

Similar Reads

  • numpy.ldexp() in Python
    In Python, numpy.ldexp(arr1, arr2[, out]) function returns arr1 * (2**arr2), element-wise. This is also called as inverse of numpy.frexp() function. Syntax: numpy.ldexp()Parameters: arr1: [array_like] Array of multipliers. arr2: [array_like, int] Array of twos exponents. out: [ndarray, optional] Out
    1 min read
  • numpy.defchararray.multiply() in Python
    numpy.core.defchararray.multiply(arr, n): Concatenates strings 'n' times element-wise. Parameters: arr : array-like or string. n : [array-like] no. of times we want to concatenate. Returns : Concatenated String 'n' times element-wise. Code #1: # Python Program illustrating # numpy.char.multiply() me
    1 min read
  • numpy.mod() in Python
    numpy.mod() is another function for doing mathematical operations in numpy.It returns element-wise remainder of division between two array arr1 and arr2 i.e. arr1 % arr2 .It returns 0 when arr2 is 0 and both arr1 and arr2 are (arrays of) integers. Syntax : numpy.mod(arr1, arr2, /, out=None, *, where
    2 min read
  • numpy.char.multiply() function in Python
    The multiply() method of the char class in the NumPy module is used for element-wise string multiple concatenation. numpy.char.multiply()Syntax : numpy.char.multiply(a, i)Parameters : a : array of str or unicodei : number of times to be repeatedReturns : Array of strings Example 1 : Using the method
    1 min read
  • numpy.inner() in python
    numpy.inner(arr1, arr2): Computes the inner product of two arrays. Parameters : arr1, arr2 : array to be evaluated. Return: Inner product of the two arrays. Code #1 : # Python Program illustrating # numpy.inner() method import numpy as geek # Scalars product = geek.inner(5, 4) print("inner Prod
    1 min read
  • numpy.negative() in Python
    numpy.negative() function is used when we want to compute the negative of array elements. It returns element-wise negative value of an array or negative value of a scalar. Syntax : numpy.negative(arr, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, ext
    2 min read
  • numpy.nansum() in Python
    numpy.nansum()function is used when we want to compute the sum of array elements over a given axis treating Not a Numbers (NaNs) as zero. Syntax : numpy.nansum(arr, axis=None, dtype=None, out=None, keepdims='no value') Parameters : arr : [array_like] Array containing numbers whose sum is desired. If
    3 min read
  • numpy.invert() in Python
    numpy.invert() function is used to Compute the bit-wise Inversion of an array element-wise. It computes the bit-wise NOT of the underlying binary representation of the integers in the input arrays. For signed integer inputs, the two’s complement is returned. In a two’s-complement system negative num
    2 min read
  • numpy.nancumsum() in Python
    numpy.nancumsum() function is used when we want to compute the cumulative sum of array elements over a given axis treating Not a Numbers (NaNs) as zero. The cumulative sum does not change when NaNs are encountered and leading NaNs are replaced by zeros. Zeros are returned for slices that are all-NaN
    3 min read
  • numpy.nancumprod() in Python
    numpy.nancumprod() function is used when we want to compute the cumulative product of array elements over a given axis treating Not a Numbers (NaNs) as one. The cumulative product does not change when NaNs are encountered and leading NaNs are replaced by ones. Ones are returned for slices that are a
    3 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