I will help you to understand how to multiply an array by a scalar in Python in this tutorial. As a data scientist working on a project for a US-based company, I had a requirement to multiply an array by a scalar. After researching various methods, I discovered several effective ways to achieve this. I will explain these techniques, along with examples and screenshots of executed example code.
Introduction to NumPy
Python NumPy is a basic package for scientific computing in Python. It provides support for arrays, matrices, and many mathematical functions. To begin, you need to install NumPy if you haven’t already:
pip install numpyOnce installed, you can import NumPy in your Python script:
import numpy as npRead How to Find the Maximum Value in Python Using the max() Function?
Basic Python Array Creation
Let’s create a basic NumPy array to use in our examples. Imagine you have a list of sales figures for four stores in different cities: New York, Los Angeles, Chicago, and Houston.
sales = np.array([1500, 2000, 1700, 1300])Check out How to Find the Closest Value in an Array Using Python
Multiplying a Python Array by a Scalar
Multiplying an array by a scalar is simple with NumPy. You can use the * operator or the np.multiply() function.
Read How to Remove Duplicates from a Sorted Array in Python
1. Use the * Operator
The simplest way to multiply an array by a scalar is by using the * operator:
scaled_sales = sales * 1.1
print(scaled_sales)Output:
[1650. 2200. 1870. 1430.]Let me show you the screenshot of the example code which I executed.

In this example, we are scaling the sales figures by 10%, which can represent a projected growth rate.
Check out How to Iterate Through a 2D Array in Python
2. Use the np.multiply()function
Alternatively, you can use the np.multiply() function, which is particularly useful when you need to multiply two arrays element-wise:
scaled_sales = np.multiply(sales, 1.1)
print(scaled_sales)Output:
[1650. 2200. 1870. 1430.]Let me show you the screenshot of the example code which I executed.

This will produce the same result as the * operator.
Read How to Distinguish Between Arrays and Lists in Python
Handling Multi-Dimensional Python Arrays
NumPy also supports multi-dimensional arrays, which are essential in more complex data structures such as matrices. Let’s consider a 2D array representing quarterly sales for the same stores:
quarterly_sales = np.array([
[1500, 2000, 1700, 1300],
[1600, 2100, 1800, 1400],
[1700, 2200, 1900, 1500],
[1800, 2300, 2000, 1600]
])To multiply each element of this 2D array by a scalar, you can use the same methods:
1. Use the * Operator
scaled_quarterly_sales = quarterly_sales * 1.1
print(scaled_quarterly_sales)Output:
[[1650. 2200. 1870. 1430.]
[1760. 2310. 1980. 1540.]
[1870. 2420. 2090. 1650.]
[1980. 2530. 2200. 1760.]]Let me show you the screenshot of the example code which I executed.

Check out How to Append to an Array in Python
2. Use the np.multiply()function
scaled_quarterly_sales = np.multiply(quarterly_sales, 1.1)
print(scaled_quarterly_sales)Output:
[[1650. 2200. 1870. 1430.]
[1760. 2310. 1980. 1540.]
[1870. 2420. 2090. 1650.]
[1980. 2530. 2200. 1760.]]Both methods will scale each element in the 2D array by 10%.
Read How to Find the Maximum Value in an Array in Python
Example
Let’s consider a real-world example where you need to adjust the prices of products in different stores across the USA. Suppose you have a 2D array representing the prices of four products in four stores:
prices = np.array([
[10.5, 12.0, 9.5, 11.0],
[11.5, 13.0, 10.5, 12.0],
[12.5, 14.0, 11.5, 13.0],
[13.5, 15.0, 12.5, 14.0]
])If you need to apply a 5% discount to all prices, you can multiply the array by 0.95:
discounted_prices = prices * 0.95
print(discounted_prices)Output :
[[ 9.975 11.4 9.025 10.45 ]
[10.925 12.35 9.975 11.4 ]
[11.875 13.3 10.925 12.35 ]
[12.825 14.25 11.875 13.3 ]]Check out How to Create an Array of Zeros in Python
Broadcast in NumPy
One of the most useful features of NumPy is broadcasting. Broadcasting allows you to perform operations on arrays of different shapes, making it easier to work with multi-dimensional data.
Read How to Print an Array with Commas in Python
Example of NumPy Broadcast
Suppose you have a 1D array representing a discount rate for each product:
discounts = np.array([0.95, 0.90, 0.85, 0.80])You can apply these discounts to the prices array using broadcasting:
discounted_prices = prices * discounts
print(discounted_prices)NumPy will automatically broadcast the discounts array to match the shape of prices, resulting in:
[[ 9.975 10.8 8.075 8.8 ]
[10.925 11.7 8.925 9.6 ]
[11.875 12.6 9.775 10.4 ]
[12.825 13.5 10.625 11.2 ]]Check out How to Find the Sum of an Array in Python
Common Issues
Data Type Issues
When multiplying arrays by scalars, it’s essential to ensure that your array’s data type is compatible with the operation. For example, if your array contains strings, NumPy will not be able to perform the multiplication. Always check and convert your data types if necessary:
sales = np.array(['1500', '2000', '1700', '1300'], dtype=int)
scaled_sales = sales * 1.1
print(scaled_sales)Handling Large Arrays
When working with large arrays, be aware of memory usage. NumPy is optimized for performance, but it’s still possible to run into memory issues with very large datasets. Consider using data types that require less memory or using memory-mapped files if necessary.
Read How to Remove Duplicates from an Array in Python
Conclusion
In this tutorial, I have explained how to multiply an array by a scalar in Python. We started with basic array creation in NumPy, We saw two methods for multiplying an array by a scalar, they use the * operator and by np.multiply()function, I also showed how to handle multi-dimensional arrays by using the same two methods, We saw some common issues with data type and handling large arrays.
You may also like to read:
- How to Check if an Array Index Exists in Python
- How to Remove NaN from Array in Python
- How to Initialize an Array in Python?

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.