You can multiply numpy arrays by scalars and it just works.

>>> import numpy as np
>>> np.array([1, 2, 3]) * 2
array([2, 4, 6])
>>> np.array([[1, 2, 3], [4, 5, 6]]) * 2
array([[ 2,  4,  6],
       [ 8, 10, 12]])

This is also a very fast and efficient operation. With your example:

>>> a_1 = np.array([1.0, 2.0, 3.0])
>>> a_2 = np.array([[1., 2.], [3., 4.]])
>>> b = 2.0
>>> a_1 * b
array([2., 4., 6.])
>>> a_2 * b
array([[2., 4.],
       [6., 8.]])
Answer from iz_ on Stack Overflow
Discussions

Multiplying each integer in a list of lists by a float
student_scores is a list of strings, not integers. You need to use int to parse the string to an integer before trying to multiply it. You currently have int wrapping the entire multiplication, which will have the result of essentially flooring the product. More on reddit.com
๐ŸŒ r/learnpython
8
1
September 21, 2024
Row multiplication in numpy array
You can take advantage of numpy's broadcasting behavior to multiply a vector against your array. Two transpositions are required due to numpy broadcasting across the last dimension - one to orientate the array in the correct way for broadcasting to do its thing and the other to re-orientate back to its original setup. import numpy as np arr = np.tile(np.arange(0, 5), 5).reshape(5, 5) print((arr.T * np.arange(1, 6)).T) More on reddit.com
๐ŸŒ r/learnpython
3
1
December 28, 2021
How to multiply two arrays of matrices in Python?
you need to use numpy for anything like this, except if it's some homework or you're just interested in seeing how it'd work in pure python More on reddit.com
๐ŸŒ r/learnpython
9
1
July 25, 2023
List multiplication with a scalar
An asterisk between a list and an integer extends the list multiple times, to give a new list containing multiple copies of the original list's elements. Each element may be any kind of object (including another list). mylist = [e1, ... en] newlist = mylist * 3 print(newlist) prints: [e1, ... en, e1, ... en, e1, ... en] This is the same for other list-like data containers, such as strings and tuples. # Strings "abc" * 3 # Returns "abcabcabc" # Tuples (1, 2, 3) * 3 # Returns (1, 2, 3, 1, 2, 3, 1, 2, 3) # List of lists [list1, list2, list3] * 3 # Returns [list1, list2, list3, list1, list2, list3, list1, list2, list3] More on reddit.com
๐ŸŒ r/learnpython
5
2
May 11, 2023
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ numpy-multiply-in-python
numpy.multiply() in Python - GeeksforGeeks
July 11, 2025 - The numpy.multiply() is a numpy function in Python which is used to find element-wise multiplication of two arrays or scalar (single value). It returns the product of two input array element by element.
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 2.1 โ€บ reference โ€บ generated โ€บ numpy.multiply.html
numpy.multiply โ€” NumPy v2.1 Manual
The product of x1 and x2, element-wise. This is a scalar if both x1 and x2 are scalars. ... Equivalent to x1 * x2 in terms of array broadcasting. ... >>> x1 = np.arange(9.0).reshape((3, 3)) >>> x2 = np.arange(3.0) >>> np.multiply(x1, x2) array([[ 0., 1., 4.], [ 0., 4., 10.], [ 0., 7., 16.]])
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-multiply-numbers-list-3-different-ways
Multiply All Numbers in the List in Python - GeeksforGeeks
We can simply use a loop (for loop) to iterate over the list elements and multiply them one by one.
Published ย  October 28, 2025
๐ŸŒ
Altcademy
altcademy.com โ€บ blog โ€บ how-to-multiply-in-python
How to multiply in Python
June 13, 2023 - In this example, we define a string called my_string and multiply it by 3, which repeats the string three times. The result is a new string with the original content repeated three times. In some cases, you may need to perform element-wise or matrix multiplication on arrays or matrices, which are common data structures in scientific computing, data science, and machine learning. Python's NumPy library is a powerful tool for working with arrays and matrices, and it provides built-in functions to perform various types of multiplication.
Find elsewhere
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ numpy-matrix-multiplication
NumPy Matrix Multiplication: Methods and Examples | DigitalOcean
August 4, 2022 - NumPy matrix multiplication can be done by the following three methods. ... If you want element-wise matrix multiplication, you can use multiply() function. import numpy as np arr1 = np.array([[1, 2], [3, 4]]) arr2 = np.array([[5, 6], [7, 8]]) arr_result = np.multiply(arr1, arr2) print(arr_result)
๐ŸŒ
APXML
apxml.com โ€บ courses โ€บ linear-algebra-fundamentals-machine-learning โ€บ chapter-3-matrix-operations โ€บ matrix-scalar-multiplication
Matrix-Scalar Multiplication
As you might expect, performing ... operator * between a NumPy array (our matrix) and a scalar. NumPy automatically handles the element-wise multiplication for you. Here's how you can perform the same calculation from our example in Python:...
๐ŸŒ
Medium
medium.com โ€บ @whyamit101 โ€บ different-ways-to-multiply-arrays-in-numpy-65aa2522e265
Different Ways to Multiply Arrays in NumPy | by why amit | Medium
February 9, 2025 - Letโ€™s dive into the three key methods: element-wise multiplication, matrix multiplication, and broadcasting. Iโ€™ll walk you through each, with detailed examples to help you follow along step by step. Think of this as a one-to-one match. Each element in one array pairs with the corresponding element in the other array to perform multiplication.
๐ŸŒ
AskPython
askpython.com โ€บ home โ€บ numpy multiply โ€“ illustrated in a simple way
NumPy multiply - Illustrated in a Simple Way - AskPython
February 16, 2023 - In the following lines, the function np.multiply(a,b) is called by passing a and b as arguments to the function where a is the NumPy array and b holds the scalar value of 10.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ multiplying each integer in a list of lists by a float
r/learnpython on Reddit: Multiplying each integer in a list of lists by a float
September 21, 2024 -

Hey guys! So I'm having trouble learning this exercise and I can't figure out why I keep getting this type error every time run this code. The task is to use a nested set of for loops to multiply each integer in a list of lists by a float

# These are all the numbers in the list
allscores = [['90', '83', '95'], ['100', '78', '89', '87', '90'], ['57', '82', '85', '89']]
# This is the nested set of for loops I used to multiply each number
for student_scores in allscores:
    for i in range(len(student_scores)):
        student_scores[i] = int(student_scores[i] * 1.05)
print("All scores after extra credit:", allscores)

after running the code, pycharm responded with this

student_scores[i] = int(student_scores[i] * 1.05)
                        ~~~~~~~~~~~~~~~~~~^~~~~~
TypeError: can't multiply sequence by non-int of type 'float'

The list output should end up looking like this

All scores after extra credit: [[94, 87, 99], [105, 81, 93, 91, 94], [59, 86, 89, 93]]

๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ multiply-the-fractional-part-of-two-numpy-arrays-with-a-scalar-value
Multiply the fractional part of two Numpy arrays with a scalar value
February 7, 2022 - import numpy as np # Creating two 2D numpy arrays using the array() method arr1 = np.array([1.7, 20.4, 100.8, 45.8, -22.7, np.nan, np.inf]) arr2 = np.array([5.1, 41.2, 120.4, 30.4, -69.6, np.nan, np.inf]) # Display the arrays print("Array 1...<br>", arr1) print("\nArray 2...<br>", arr2) # Get the type of the arrays print("\nOur Array 1 type...<br>", arr1.dtype) print("\nOur Array 2 type...<br>", arr2.dtype) # Get the dimensions of the Arrays print("\nOur Array 1 Dimensions...<br>",arr1.ndim) print("\nOur Array 2 Dimensions...<br>",arr2.ndim) # To return the fractional and integral parts of array values, use the numpy.modf() method in Python Numpy # Multiply the fractional values using the index 0 values print("\nResult...<br>",np.modf(arr1[0]*arr2[0]))
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ row multiplication in numpy array
r/learnpython on Reddit: Row multiplication in numpy array
December 28, 2021 -

Hello, help me please. I need to create an array with rows having subsequent values multiplied by the row number. For now I can just multiply all rows by one number. Something like print(arr[row * range(1, 5)]) doesn't work. How could I do row multiplication with a range of numbers?

arr = np.array([[i for i in range(5)],]*5)

print(arr)

for row in range(len(arr)):

print(arr[row]*5)

๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ stable โ€บ reference โ€บ generated โ€บ numpy.dot.html
numpy.dot โ€” NumPy v2.4 Manual
If both a and b are 2-D arrays, it is matrix multiplication, but using matmul or a @ b is preferred. If either a or b is 0-D (scalar), it is equivalent to multiply and using numpy.multiply(a, b) or a * b is preferred.
๐ŸŒ
OpenGenus
iq.opengenus.org โ€บ numpy-matrix-multiply-by-scalar
Numpy matrix multiply by scalar
import numpy as np matrix = np.array([[1, 2, 3], [4, 5, 6]]) print ("Original matrix = ") print (matrix) scalar = 2 new_matrix = matrix * scalar print ("Matrix x Scalar = ") print (new_matrix) ... As you see, all elements have been multiplied by the scalar 2. This is a better approach than traversing all elements one by one and multiplying each by a scalar. The approach presented in much more efficient in Python.
๐ŸŒ
Saturn Cloud
saturncloud.io โ€บ blog โ€บ multiply-every-element-in-a-numpy-array-a-comprehensive-guide
Multiply Every Element in a Numpy Array: A Guide | Saturn Cloud Blog
July 23, 2023 - # Multiply every element in the array by 2 arr2 = arr * 2 print(arr2) ... The np.multiply() function can also be used to perform element-wise multiplication. This function takes two arguments: the array and the scalar to multiply with.
๐ŸŒ
Python Guides
pythonguides.com โ€บ multiply-an-array-by-a-scalar-in-python
How To Multiply An Array By A Scalar In Python?
March 19, 2025 - Learn how to multiply an array by a scalar in Python using loops, list comprehensions, and NumPy's vectorized operations. Step-by-step examples make it easy.
๐ŸŒ
Codegive
codegive.com โ€บ blog โ€บ numpy_multiply_each_row_by_scalar.php
Numpy multiply each row by scalar
Learn techniques, broadcasting, and best practices to optimize your data operations in Python. [/META_DESCRIPTION] [SNIPPET] To multiply each row of a NumPy array by a scalar, the most efficient method is to leverage NumPy's broadcasting capabilities by simply using the * operator or np.multiply() ...