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
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.multiply.html
numpy.multiply — NumPy v2.4 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. ... Try it in your browser! >>> import numpy as np >>> np.multiply(2.0, 4.0) 8.0
🌐
Educative
educative.io › blog › numpy-matrix-multiplication
NumPy matrix multiplication: Get started in 5 minutes
April 30, 2026 - Try one of our courses on Python programming fundamentals: ... The matmul() function gives us the matrix product of two 2-d arrays. With this method, we can’t use scalar values for our input.
🌐
Reddit
reddit.com › r/twinegames › multiplying array by a scalar and storing it as a new array?
r/twinegames on Reddit: Multiplying array by a scalar and storing it as a new array?
May 15, 2022 -

Hi

I'm quite new to Twine, using SugarCube 2.31.1 and have a nested array that I want to extract and multiply by a scalar variable.

<<set $belief0001 to ["I believe in God",1,[0,1,2,3,1,2,1],1,14,[]]>>

<<set $belief0002 to ["Human beings are OK",2,[0,1,3,2,3,2,1],1,5,[]]>>

<<set $belief0003 to ["Reality is an illusion",3,[0,3,3,3,1,1,1],1,9,[]]>>

<<set $beliefs to [$belief0001,$belief0002,$belief0003]>>

Now what I want to do is create a new array that is the product of $beliefs[$i][2] * $beliefs[$i][3] * $beliefs[$i][4] using a <<for>> loop something like this:

<<for $i to 0; $i < $beliefs.length; $i++>>

<<set $newarray to $beliefs[$i][2] * $beliefs[$i][3] * $beliefs[$i][4]>>

<</for>>

The thing is, $beliefs[$i][2] is a nested array and it seems Twine doesn't like me multipliying it with the other two scalar variables. I also think this is affecting the $beliefs array which I don't want it to do, I want it to create an entirely new array called $newarray.

Any help appreciated!

🌐
Learn Coding Fast
learncodingfast.com › home › python programming challenge 2: multiplying matrices without numpy
Python Programming Challenge 2: Multiplying Matrices without numpy | Learn Coding Fast
August 30, 2020 - For instance, the diagram below shows how we get the number 38 by multiplying the first row (2, 3, 6) in the first matrix with the first column (1, 2, 5) in the second matrix. Clear? If you are lost, you can refer to the YouTube video below for a more detailed explanation: For those of you who are familiar with using Python for data science, you have probably used the numpy module to multiply matrices before.
🌐
Problem Solving with Python
problemsolvingwithpython.com › 05-NumPy-and-Arrays › 05.07-Array-Opperations
Array Operations - Problem Solving with Python
Scalars can be added and subtracted from arrays and arrays can be added and subtracted from each other: ... NumPy array can be multiplied by each other using matrix multiplication. These matrix multiplication methods include element-wise multiplication, the dot product, and the cross product. The standard multiplication sign in Python ...
Find elsewhere
🌐
Delft Stack
delftstack.com › home › howto › numpy › multiply array with scalar in python
How to Multiply Array With Scalar in Python | Delft Stack
March 11, 2025 - The simplest way to multiply an array by a scalar in Python is by using the * operator. This method is intuitive and easy to use, especially for those who are familiar with basic arithmetic operations in Python.
🌐
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]]

🌐
IncludeHelp
includehelp.com › python › numpy-multiply-array-with-scalar.aspx
Python - NumPy: Multiply array with scalar
December 21, 2023 - In this tutorial, we are going to learn how to multiply a NumPy array with a scalar value in Python?
🌐
Studyopedia
studyopedia.com › home › scalar operations on numpy arrays
Scalar operations on Numpy arrays - Studyopedia
October 18, 2023 - Scalar operations on Numpy arrays, include performing addition or subtraction, or multiplication on each element of a Numpy array.
🌐
SciPy Lecture Notes
scipy-lectures.org › intro › numpy › operations.html
1.4.2. Numerical operations on arrays — Scipy lecture notes
1. Getting started with Python for science » · 1.4. NumPy: creating and manipulating numerical data » · Collapse document to compact view · Edit Improve this page: Edit it on Github. Section contents · Elementwise operations · Basic reductions · Broadcasting · Array shape manipulation · Sorting data · Summary · With scalars: >>> a = np.array([1, 2, 3, 4]) >>> a + 1 ·
🌐
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.
🌐
Reddit
reddit.com › r/learnpython › numpy: how to scale a rectangular array by a vector of scalars?
r/learnpython on Reddit: NumPy: How to scale a rectangular array by a vector of scalars?
October 12, 2022 -
>>> b = np.arange(12).reshape([3, 4])
>>> a = np.arange(3)
>>> b
array([[ 0,  1,  2,  3],
       [ 4,  5,  6,  7],
       [ 8,  9, 10, 11]])
>>> a
array([0, 1, 2])
>>> a * b
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: operands could not be broadcast together with shapes (3,) (3,4) 
>>> b = np.arange(9).reshape([3, 3])
>>> a * b
array([[ 0,  1,  4],
       [ 0,  4, 10],
       [ 0,  7, 16]])
🌐
GeeksforGeeks
geeksforgeeks.org › numpy-multiply-in-python
numpy.multiply() in Python - GeeksforGeeks
April 17, 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.
🌐
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 - Here’s where NumPy gets smart. Even if your arrays have different shapes, NumPy can sometimes align them automatically using broadcasting. This makes operations possible without manual reshaping. For instance, let’s multiply a 2D array by a scalar:
🌐
Statology
statology.org › home › how to perform matrix scalar multiplication in python
How to Perform Matrix Scalar Multiplication in Python
July 20, 2024 - Matrix scalar multiplication is a straightforward yet powerful operation in matrix algebra. This guide not only provides a practical introduction to applying scalar multiplication to matrices in Python but also highlights the operation’s commutative nature and its real-world applications.
🌐
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.