How to multiply array by scalar in Numpy?

Let’s see how to multiply array by scalar in Numpy Python library.
numpy array multiply by scalar

How to multiply array by scalar in Python

To multiply an array by a scalar, simply use the asterisk (*) operator. No specific NumPy function is required for this operation.

import numpy as np

my_array = np.array([1, 2, 3, 4, 5])
print(my_array)

my_scalar = 5
multiplied_array = my_array * my_scalar

print(multiplied_array)

The given array has been multiplied by the specified scalar, meaning that each element of the array has been multiplied by that scalar.

See also  How to mask array in Numpy?

Python simply multiplies each item by the number without any additional operations.