Extend B to 2D and then divide -

A/B[:,None].astype(float)

Sample run -

In [9]: A
Out[9]: 
array([[ 2,  4],
       [ 6,  8],
       [10, 12]])

In [10]: B
Out[10]: array([1, 2, 4])

In [11]: A/B[:,None].astype(float)
Out[11]: 
array([[ 2. ,  4. ],
       [ 3. ,  4. ],
       [ 2.5,  3. ]])

Or use from __future__ import division that takes care of division to result in a floating pt array -

In [14]: from __future__ import division

In [15]: A/B[:,None]
Out[15]: 
array([[ 2. ,  4. ],
       [ 3. ,  4. ],
       [ 2.5,  3. ]])

Performance boost with multiplication by reciprocal -

In [32]: A = np.random.rand(300,200)

In [33]: B = np.random.rand(300)

In [34]: from __future__ import division

In [35]: %timeit A/B[:,None]
1000 loops, best of 3: 336 µs per loop

In [36]: %timeit A*(1.0/B[:,None])
10000 loops, best of 3: 101 µs per loop

More info on this could be found here. Also, one needs to be careful using this method though, if the values of B are extremely close to 0.

Answer from Divakar on Stack Overflow
🌐
NumPy
numpy.org › doc › stable › user › basics.broadcasting.html
Broadcasting — NumPy v2.4 Manual
>>> from numpy import array, argmin, sqrt, sum >>> observation = array([111.0, 188.0]) >>> codes = array([[102.0, 203.0], ... [132.0, 193.0], ... [45.0, 155.0], ... [57.0, 173.0]]) >>> diff = codes - observation # the broadcast happens here >>> dist = sqrt(sum(diff**2,axis=-1)) >>> argmin(dist) 0 · In this example, the observation array is stretched to match the shape of the codes array: Observation (1d array): 2 Codes (2d array): 4 x 2 Diff (2d array): 4 x 2
🌐
Note.nkmk.me
note.nkmk.me › home › python › numpy
NumPy: Broadcasting rules and examples | note.nkmk.me
October 13, 2021 - For example, in the case of images, a color image is a 3D array whose shape is (height, width, 3) (3 means red, green, and blue), while a grayscale image is a 2D array whose shape is (height, width). ... In the case of computing the value of each color in a color image and the value of a grayscale image, it is impossible to broadcast even if the height and width are the same. You need to add a dimension to the end of the grayscale image with np.newaxis, np.expand_dims(), and so on. NumPy: Add new dimensions to ndarray (np.newaxis, np.expand_dims)
🌐
NumPy
numpy.org › devdocs › user › theory.broadcasting.html
Array broadcasting in Numpy — NumPy v2.5.dev0 Manual
Please refer to the updated Broadcasting document · Created using Sphinx 7.2.6
🌐
SciPy
docs.scipy.org › doc › numpy-1.10.4 › user › basics.broadcasting.html
Broadcasting — NumPy v1.10 Manual
Image (3d array): 256 x 256 x 3 Scale (1d array): 3 Result (3d array): 256 x 256 x 3 · When either of the dimensions compared is one, the other is used. In other words, dimensions with size 1 are stretched or “copied” to match the other. In the following example, both the A and B arrays have axes with length one that are expanded to a larger size during the broadcast operation: A (4d array): 8 x 1 x 6 x 1 B (3d array): 7 x 1 x 5 Result (4d array): 8 x 7 x 6 x 5 ... A (2d ...
🌐
Python Like You Mean It
pythonlikeyoumeanit.com › Module3_IntroducingNumpy › Broadcasting.html
Array Broadcasting — Python Like You Mean It
See that entry (i, j) of the resulting array corresponds to x_1d[i] * y[j]. Through the use of simple reshaping, shrewdly inserting size-1 dimensions allowed us to coerce NumPy into performing exactly the combination-multiplication that we desired. Furthermore, a keen understanding of what ...
🌐
Python Data Science Handbook
jakevdp.github.io › PythonDataScienceHandbook › 02.05-computation-on-arrays-broadcasting.html
Computation on Arrays: Broadcasting | Python Data Science Handbook
Broadcasting allows these types of binary operations to be performed on arrays of different sizes–for example, we can just as easily add a scalar (think of it as a zero-dimensional array) to an array: ... We can think of this as an operation that stretches or duplicates the value 5 into the array [5, 5, 5], and adds the results. The advantage of NumPy's broadcasting is that this duplication of values does not actually take place, but it is a useful mental model as we think about broadcasting.
🌐
Afdataschool
afdataschool.github.io › numpy › 03-broadcasting › index.html
Numpy: Broadcasting
May 27, 2019 - To obtain a column array from a 1D array we need to convert it to 2D array of four rows and one column. In NumPy we can add singular dimensions (dimensions of size 1) by a special object np.newaxis: a.shape a_column = a[:, np.newaxis] a_column.shape a_column ...
🌐
Finxter
blog.finxter.com › home › learn python blog › numpy broadcasting – a simple tutorial
NumPy Broadcasting - A Simple Tutorial - Be on the Right Side of Change
July 28, 2021 - Here is a nice visualization from the documentation of how NumPy arrays will be broadcasted together: A (2d array): 5 x 4 B (1d array): 1 Result (2d array): 5 x 4 A (2d array): 5 x 4 B (1d array): 4 Result (2d array): 5 x 4 A (3d array): 15 x 3 x 5 B (3d array): 15 x 1 x 5 Result (3d array): 15 x 3 x 5 A (3d array): 15 x 3 x 5 B (2d array): 3 x 5 Result (3d array): 15 x 3 x 5 A (3d array): 15 x 3 x 5 B (2d array): 3 x 1 Result (3d array): 15 x 3 x 5
Find elsewhere
🌐
University of Texas at Austin
het.as.utexas.edu › HET › Software › Numpy › user › basics.broadcasting.html
Broadcasting — NumPy v1.9 Manual
Image (3d array): 256 x 256 x 3 Scale (1d array): 3 Result (3d array): 256 x 256 x 3 · When either of the dimensions compared is one, the other is used. In other words, dimensions with size 1 are stretched or “copied” to match the other. In the following example, both the A and B arrays have axes with length one that are expanded to a larger size during the broadcast operation: A (4d array): 8 x 1 x 6 x 1 B (3d array): 7 x 1 x 5 Result (4d array): 8 x 7 x 6 x 5 ... A (2d ...
🌐
YouTube
youtube.com › watch
NumPy Broadcasting: 1D to 2D Arrays Explained | Python Tutorial for Beginners - YouTube
📊 Master NumPy Broadcasting! Learn how to broadcast 1D arrays to 2D arrays in Python.In this comprehensive NumPy tutorial, you'll discover how broadcasting ...
Published   October 29, 2025
🌐
Board Infinity
boardinfinity.com › blog › numpy-broadcasting
Numpy Broadcasting | Board Infinity
August 18, 2025 - The rules for broadcasting are ... 1D array of shape (4), you can broadcast the 1D array to the 2D array by duplicating it along the first dimension....
🌐
Paris-swc
paris-swc.github.io › advanced-numpy-lesson › 03-broadcasting.html
Software Carpentry: Advanced NumPy
In order to broadcast, the size of the trailing axes for both arrays in an operation must either be the same or one of them must be one. This does indeed work for the three addition from the figure · a: 4 x 3 b: 4 x 3 result: 4 x 3 a: 4 x 3 b: 3 result: 4 x 3 a: 4 x 1 b: 3 result: 4 x 3 ... ...
🌐
NumPy
numpy.org › devdocs › user › basics.broadcasting.html
Broadcasting — NumPy v2.5.dev0 Manual
>>> from numpy import array, argmin, sqrt, sum >>> observation = array([111.0, 188.0]) >>> codes = array([[102.0, 203.0], ... [132.0, 193.0], ... [45.0, 155.0], ... [57.0, 173.0]]) >>> diff = codes - observation # the broadcast happens here >>> dist = sqrt(sum(diff**2,axis=-1)) >>> argmin(dist) 0 · In this example, the observation array is stretched to match the shape of the codes array: Observation (1d array): 2 Codes (2d array): 4 x 2 Diff (2d array): 4 x 2
🌐
w3resource
w3resource.com › python-exercises › numpy › using-numpy-to-divide-2d-arrays-by-1d-arrays-with-broadcasting.php
Using NumPy to divide 2D arrays by 1D arrays with Broadcasting
August 30, 2025 - Learn how to efficiently divide each row of a 2D array by a 1D array using NumPy's broadcasting feature. Step-by-step explanation and sample code provided.
🌐
w3resource
w3resource.com › python-exercises › numpy › add-1d-array-to-each-row-of-2d-array-using-np-dot-add-in-numpy.php
Add 1D array to each Row of 2D array using np.add in NumPy
September 3, 2025 - Use the np.add "ufunc" to add the 1D array to each row of the 2D array. NumPy automatically broadcasts the 1D array to match the shape of the 2D array.
🌐
NumPy
numpy.org › doc › 1.20 › user › theory.broadcasting.html
Array Broadcasting in Numpy — NumPy v1.20 Manual
We can think of the scalar b being stretched during the arithmetic operation into an array with the same shape as a. The new elements in b, as shown in Figure 1, are simply copies of the original scalar. The stretching analogy is only conceptual. numpy is smart enough to use the original scalar value without actually making copies so that broadcasting operations are as memory and computationally efficient as possible.
🌐
LabEx
labex.io › tutorials › numpy-numpy-broadcasting-fundamentals-86412
Mastering NumPy Broadcasting: Elevate Your Data Manipulation Skills | LabEx
import numpy as np a = np.array([[1, 2, 3], [4, 5, 6]]) b = np.array([10, 20, 30]) print(a + b) The output will be: [[11 22 33] [14 25 36]] The 1D array is broadcast across the second axis of the 2D array and added to each column.