For elementwise multiplication of matrix objects, you can use numpy.multiply:

import numpy as np
a = np.array([[1,2],[3,4]])
b = np.array([[5,6],[7,8]])
np.multiply(a,b)

Result

array([[ 5, 12],
       [21, 32]])

However, you should really use array instead of matrix. matrix objects have all sorts of horrible incompatibilities with regular ndarrays. With ndarrays, you can just use * for elementwise multiplication:

a * b

If you're on Python 3.5+, you don't even lose the ability to perform matrix multiplication with an operator, because @ does matrix multiplication now:

a @ b  # matrix multiplication
Answer from Rahul K P on Stack Overflow
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.multiply.html
numpy.multiply — NumPy v2.1 Manual
The product of x1 and x2, element-wise. This is a scalar if both x1 and x2 are scalars. ... Equivalent to x1 * x2 in terms of array broadcasting. ... >>> x1 = np.arange(9.0).reshape((3, 3)) >>> x2 = np.arange(3.0) >>> np.multiply(x1, x2) array([[ 0., 1., 4.], [ 0., 4., 10.], [ 0., 7., 16.]])
Discussions

Element-wise multiply arrays with different axes [numpy]

Are you using arrays? If yes, you're in luck because the '*' is element by element multiplication and not matrix multiplication. Therefore:

import numpy as np

A = np.array([5, 4, 3, 2, 1])
B = np.array([[ 123.,    4.,    0.,    0.,    0.],
                    [   0.,    0.,    0.,   45.,    0.],
                    [   0.,    0.,  100.,   -5.,    0.]])

C = np.tile(A, (M, 1)) * B

D = A * B 

And as result you get:

>>> C
array([[ 615.,   16.,    0.,    0.,    0.],
       [   0.,    0.,    0.,   90.,    0.],
       [   0.,    0.,  300.,  -10.,    0.]])
>>> D
array([[ 615.,   16.,    0.,    0.,    0.],
       [   0.,    0.,    0.,   90.,    0.],
       [   0.,    0.,  300.,  -10.,    0.]])

And if you're working with matrices, use multiply() to have element-wise multiplication (which is what you're trying to do)

https://docs.scipy.org/doc/numpy-dev/user/numpy-for-matlab-users.html#array-or-matrix-which-should-i-use

More on reddit.com
🌐 r/learnpython
5
9
February 23, 2016
How to do elementwise multiplication of two vectors using NumPy?
By using these methods, you can efficiently perform element-wise multiplication on vectors using NumPy in Python. More on designgurus.io
🌐 designgurus.io
1
10
September 29, 2024
Multiply array times itself element wise in python?

What do you think is going on under the hood besides looping through and squaring every element in the array, in any language? In some languages you could end up lazily-evaluating it so the squaring isn't done on a given element until that element is requested, but otherwise there's no way to get around the fact that you have to square every single element one at a time.

In any case, if you just want a way to do it in fewer lines, you could do this:

map(lambda x: x*x, my_array)

or

[x*x for x in my_array]
More on reddit.com
🌐 r/learnprogramming
5
4
June 4, 2012
Composition of element-wise multiplication and lmul!
Option 2 will save you an allocation but the difference will be pretty minor since the matmul will take way more time than the elementwise mul. More on reddit.com
🌐 r/Julia
2
5
February 16, 2023
🌐
GeeksforGeeks
geeksforgeeks.org › python › numpy-multiply-in-python
numpy.multiply() in Python - GeeksforGeeks
July 11, 2025 - The numpy.multiply() is a numpy function in Python which is used to find element-wise multiplication of two arrays or scalar (single value).
🌐
Medium
medium.com › @amit25173 › numpy-element-wise-multiplication-306fd4cb5841
NumPy Element-wise Multiplication | by Amit Yadav | Medium
January 25, 2025 - Using the * operator, we multiply each element from array1 with the corresponding element in array2. ... The output is a new array: [4, 10, 18]. You might be wondering, “Why use NumPy instead of a plain Python list?”
🌐
Saturn Cloud
saturncloud.io › blog › multiply-every-element-in-a-numpy-array-a-comprehensive-guide
Multiply Every Element in a Numpy Array: A Guide | Saturn Cloud Blog
July 23, 2023 - # Multiply every element in the array by 2 arr3 = np.multiply(arr, 2) print(arr3) ... Both methods will give the same result. The choice between the two often comes down to personal preference and the specific requirements of your code. Numpy also allows for element-wise multiplication between two arrays of the same shape.
🌐
Vultr Docs
docs.vultr.com › python › third-party › numpy › multiply
Python Numpy multiply() - Multiply Array Elements | Vultr Docs
November 18, 2024 - The numpy.multiply() function is essential for performing efficient element-wise multiplication of arrays in Python using the NumPy library. Whether you are working with scalars and arrays or two different-sized matrices, numpy.multiply() supports ...
Find elsewhere
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.multiply.html
numpy.multiply — NumPy v2.5.dev0 Manual
The product of x1 and x2, element-wise. This is a scalar if both x1 and x2 are scalars. ... Equivalent to x1 * x2 in terms of array broadcasting. ... Try it in your browser! >>> import numpy as np >>> np.multiply(2.0, 4.0) 8.0
🌐
Reddit
reddit.com › r/learnpython › element-wise multiply arrays with different axes [numpy]
r/learnpython on Reddit: Element-wise multiply arrays with different axes [numpy]
February 23, 2016 -

Hi everyone,

I'm trying to achieve something with the least possible overhead. I have a one-dimensional array A whose shape is (N,) and another one B whose shape is (M,N). What I'm trying to do is to element-wise multiply each column of B (axis 1) by A. Basically something like this:

C = np.zeros((M,N))
for m in range(M):
    C[m,:] = A*B[m,:]

This can also be achieved more succintly with:

C = np.tile(A, (M, 1))*B

The problem with the first approach is that it requires a for, and the problem with the second is that is unnecessarily creates a temporary array. I was wondering if there was some way to do this with some funky numpy stuff, perhaps with some tricky broadcasting but I haven't been able to come up with anything. Hopefully you will!!

🌐
GeeksforGeeks
geeksforgeeks.org › numpy › multiplication-two-matrices-single-line-using-numpy-python
Multiplication of two Matrices in Single line using Numpy in Python - GeeksforGeeks
August 6, 2024 - 2. Using Numpy : Multiplication using Numpy also know as vectorization which main aim to reduce or remove the explicit use of for loops in the program by which computation becomes faster. Numpy is a build in a package in python for array-processing and manipulation.For larger matrix operations we use numpy python package which is 1000 times faster than iterative one method.
🌐
GeeksforGeeks
geeksforgeeks.org › machine learning › numpy-vector-multiplication
NumPy | Vector Multiplication - GeeksforGeeks
July 12, 2025 - NumPy is a Python library used for performing numerical computations. It provides an efficient way to work with vectors and matrices especially when performing vector multiplication operations.
🌐
Udemy
udemy.com › development
Full-Stack AI Engineer 2026: ML, Deep Learning, GenerativeAI
February 3, 2026 - In this lecture, you’ll learn how NumPy arrays revolutionize computation by allowing fast, vectorized operations far beyond standard Python lists. You’ll practice creating arrays, slicing, reshaping, broadcasting, and performing matrix operations. By building mini examples like statistical summaries, data normalization, and matrix multiplication, you’ll see how NumPy supports the math behind deep learning algorithms and neural networks.
Rating: 4.4 ​ - ​ 255 votes
🌐
CodeChef
codechef.com › roadmap › data-structures-and-algorithms
Data Structures & Algorithms Roadmap – Learn DSA Step-by-Step
Start your DSA journey with our structured roadmap that takes you from fundamentals—like arrays and linked lists—to advanced topics such as dynamic programming and graph algorithms. Each stage includes hands-on challenges and over 450 practice problems to reinforce your coding skills.
🌐
Codegive
codegive.com › blog › numpy_matrix_multiplication_element_wise.php
Numpy matrix multiplication element wise
CodeGive AI supports popular languages like Python, JavaScript, PHP, C#, Java, Go, and SQL. You can switch between frameworks such as React, Laravel, Flask, or Node.js without needing to rewrite logic manually.
🌐
TutorialsPoint
tutorialspoint.com › numpy › numpy_element_wise_matrix_operations.htm
NumPy - Element-wise Matrix Operations
Efficiency: Element-wise operations ... Python loops to perform the same operations. In NumPy, following are the common element-wise matrix operations − · Element-wise Addition: Adding corresponding elements of two matrices. Element-wise Subtraction: Subtracting corresponding elements of two matrices. Element-wise Multiplication: Multiplying ...
Top answer
1 of 1
10
Element-wise multiplication of two vectors (also known as the Hadamard product) involves multiplying corresponding elements from each vector to produce a new vector of the same length. In NumPy, this can be easily achieved using either the * operator or the numpy.multiply function. Here's how you can perform element-wise multiplication with NumPy: 1. Using the * Operator The simplest way to perform element-wise multiplication is by using the * operator between two NumPy arrays (vectors). Example: import numpy as np # Define two vectors vector_a = np.array([1, 2, 3, 4]) vector_b = np.array([5, 6, 7, 8]) # Element-wise multiplication result = vector_a * vector_b print("Vector A:", vector_a) print("Vector B:", vector_b) print("Element-wise multiplication:", result) Output: Vector A: [1 2 3 4] Vector B: [5 6 7 8] Element-wise multiplication: [ 5 12 21 32] 2. Using numpy.multiply Alternatively, you can use the numpy.multiply function to achieve the same result. Example: import numpy as np # Define two vectors vector_a = np.array([1, 2, 3, 4]) vector_b = np.array([5, 6, 7, 8]) # Element-wise multiplication using numpy.multiply result = np.multiply(vector_a, vector_b) print("Element-wise multiplication:", result) Output: Element-wise multiplication: [ 5 12 21 32] Important Considerations Same Shape or Broadcastable Shapes:For element-wise multiplication to work, the two vectors must have the same shape. Alternatively, NumPy's broadcasting rules can apply if the shapes are compatible. Broadcasting allows NumPy to perform operations on arrays of different shapes under certain conditions.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-multiply-two-list
Python - Multiply Two Lists - GeeksforGeeks
July 12, 2025 - Explanation: List comprehension iterates over the indices of a and b multiplying corresponding elements (a[i] * b[i]). zip() function pairs corresponding elements from both lists allowing for element-wise multiplication using list comprehension.
🌐
GeeksforGeeks
geeksforgeeks.org › deep learning › deep-learning-introduction-to-long-short-term-memory
What is LSTM - Long Short Term Memory? - GeeksforGeeks
+1. Finally, this transformed cell state is multiplied element-wise with · o_t​ to produce the hidden state · h_t: h_t = o_t \odot \tanh(C_t) Here: o_t​ is the output gate activation. C_t​ is the current cell state. \odot represents element-wise multiplication.
Published   April 14, 2026
🌐
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.matmul.html
numpy.matmul — NumPy v2.2 Manual
Multiplication by scalars is not allowed, use * instead. Stacks of matrices are broadcast together as if the matrices were elements, respecting the signature (n,k),(k,m)->(n,m): >>> a = np.ones([9, 5, 7, 4]) >>> c = np.ones([9, 5, 4, 3]) >>> np.dot(a, c).shape (9, 5, 7, 9, 5, 3) >>> np.matmul(a, c).shape (9, 5, 7, 3) >>> # n is 7, k is 4, m is 3 · The matmul function implements the semantics of the @ operator introduced in Python 3.5 following PEP 465.