Let’s see how to multiply array by scalar in Numpy Python library.
How to multiply array by scalar in Python
To multiply array by scalar you just need to use usual asterisk. You don’t need any dedicated Numpy function for that purpose.
import numpy as np array = np.array([1, 2, 3, 4, 5]) print(array) scalar = 5 multiplied_array = array * scalar print(multiplied_array)
Given array has been multiplied by given scalar. Meaning that every element of array has been multiply by that scalar.
Python just multiply items by the number and does nothing else.