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
January 31, 2021 - 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
🌐
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!

🌐
Educative
educative.io › blog › numpy-matrix-multiplication
NumPy matrix multiplication: Get started in 5 minutes
2 weeks ago - 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.
🌐
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.
🌐
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.
Find elsewhere
🌐
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]])
🌐
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 - There are two primary methods you can use: the straightforward * operator and the more versatile numpy.multiply() function. Each method has its own advantages and can be useful in different scenarios. In this article, we will explore these methods in detail and provide clear code examples to guide you through the process. By the end, you’ll be well-equipped to handle array-scalar multiplication in your Python projects.
🌐
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 ...
🌐
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?
🌐
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.
🌐
McNeel Forum
discourse.mcneel.com › scripting
Multiplying Array with single value - Scripting - McNeel Forum
February 7, 2015 - Hi, I am stuck with a very basic problem. I need to multiply one value with an array. A = 5.0 B= Array(1,2,…) C= A*B I am getting error Type mismatch. Is there any library in Rhinoscript which I can use to perform s…
🌐
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:
🌐
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
🌐
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.
🌐
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 ·