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 โ€บ stable โ€บ reference โ€บ generated โ€บ numpy.multiply.html
numpy.multiply โ€” NumPy v2.4 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
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?
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. More on designgurus.io
๐ŸŒ designgurus.io
1
10
September 29, 2024
Why can't NumPy multiply these matrices?
Matrix multiplication is just about your two matrices being the same size. What has to happen with matrices, is that the number of columns of your first matrix must equal the number of rows of the second matrix in order to be multiplied. In other words, if you write out the sizes of the two matrices that you are multiplying, the two โ€œinsideโ€ dimensions must be the same. Right now, you are multiplying matrices with sizes: 3 x (4) * (3) x 4 Those two in parentheses must be the same. More on reddit.com
๐ŸŒ r/learnpython
5
1
February 1, 2022
Row multiplication in numpy array
You can take advantage of numpy's broadcasting behavior to multiply a vector against your array. Two transpositions are required due to numpy broadcasting across the last dimension - one to orientate the array in the correct way for broadcasting to do its thing and the other to re-orientate back to its original setup. import numpy as np arr = np.tile(np.arange(0, 5), 5).reshape(5, 5) print((arr.T * np.arange(1, 6)).T) More on reddit.com
๐ŸŒ r/learnpython
3
1
December 28, 2021
๐ŸŒ
NumPy
numpy.org โ€บ devdocs โ€บ reference โ€บ generated โ€บ numpy.multiply.html
numpy.multiply โ€” NumPy v2.6.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
๐ŸŒ
Medium
medium.com โ€บ @amit25173 โ€บ numpy-element-wise-multiplication-306fd4cb5841
NumPy Element-wise Multiplication | by Amit Yadav | Medium
January 25, 2025 - Thatโ€™s exactly what element-wise multiplication does โ€” nothing more, nothing less. In NumPy, element-wise multiplication means multiplying each element of one array with the matching element of another array.
๐ŸŒ
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).
Find elsewhere
๐ŸŒ
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 ...
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ numpy element wise multiplication
NumPy Element Wise Multiplication - Spark By {Examples}
March 27, 2024 - The NumPy multiply() function can be used to compute the element-wise multiplication of two arrays with the same shape, as well as multiply an array with
๐ŸŒ
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!!

๐ŸŒ
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 - The * operator can be used to multiply every element in a numpy array by a scalar. # Multiply every element in the array by 2 arr2 = arr * 2 print(arr2) ... The np.multiply() function can also be used to perform element-wise multiplication.
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.
๐ŸŒ
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.]])
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ numpy-efficient-numpy-array-multiplication-operations-5007
NumPy Array Multiplication | Python Scientific Computing | LabEx
The numpy.multiply function performs element-wise multiplication between two arrays. The two arrays must have the same shape.
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 2.1 โ€บ reference โ€บ generated โ€บ numpy.matmul.html
numpy.matmul โ€” NumPy v2.1 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):
๐ŸŒ
JAX Documentation
docs.jax.dev โ€บ en โ€บ latest โ€บ _autosummary โ€บ jax.numpy.multiply.html
jax.numpy.multiply โ€” JAX documentation
Multiply two arrays element-wise. JAX implementation of numpy.multiply. This is a universal function, and supports the additional APIs described at jax.numpy.ufunc.
๐ŸŒ
Finxter
blog.finxter.com โ€บ home โ€บ learn python blog โ€บ [numpy * operator] element-wise multiplication in python
[Numpy * Operator] Element-wise Multiplication in Python - Be on the Right Side of Change
February 25, 2025 - If you start with two NumPy arrays a and b instead of two lists, you can simply use the asterisk operator * to multiply a * b element-wise and get the same result:
๐ŸŒ
Data Science Parichay
datascienceparichay.com โ€บ home โ€บ blog โ€บ numpy โ€“ elementwise multiplication of two arrays
Numpy - Elementwise multiplication of two arrays - Data Science Parichay
June 17, 2022 - You can use the numpy np.multiply() function to perform the elementwise multiplication of two arrays. Alternatively, you can also use the * operator.
๐ŸŒ
Parag Kalra
paragkalra.com โ€บ home โ€บ dot vs element-wise multiplication
Dot vs Element-wise multiplication - Parag Kalra
January 2, 2024 - It is performed using numpy.multiply or using the * operator. It implies multiplying corresponding elements of arrays directly.