Elementwise multiplication in Python equivalent to Matlab

For numerical processing, you should use NumPy. Refer to NumPy for Matlab users for help getting started. Here is how you would translate your Matlab code to Python/NumPy.

import numpy as np
a = np.array([1, 2, 3])
b = np.array([1, 2, 3]).reshape(3, 1)
c = a * b
a.shape  # (3,)
b.shape  # (3, 1)

c
# array([[1, 2, 3],
#        [2, 4, 6],
#        [3, 6, 9]])

Of course, don’t forget to install NumPy.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top