How to multiply array by scalar in python
Posted on: March 12, 2021 by Deven
In this article, you will learn how to multiply array by scalar in python.
Let’s say you have 2 arrays that need to be multiplied by scalar n
.
array1 = np.array([1, 2, 3])
array2 = np.array([[1, 2], [3, 4]])
n = 5
Numpy multiply array by scalar
In order to multiply array by scalar in python, you can use np.multiply()
method.
import numpy as np
array1 = np.array([1, 2, 3])
array2 = np.array([[1, 2], [3, 4]])
n = 5
np.multiply(array1,n)
np.multiply(array2,n)
Share on social media
//