I´d suggest using meshgrid. Here is the documentation.


Example

>>> nx, ny = (3, 2)
>>> x = np.linspace(0, 1, nx)
>>> y = np.linspace(0, 1, ny)
>>> xv, yv = np.meshgrid(x, y)
>>> xv
array([[ 0. ,  0.5,  1. ],
       [ 0. ,  0.5,  1. ]])
>>> yv
array([[ 0.,  0.,  0.],
       [ 1.,  1.,  1.]])

linspace args:

  1. Start value
  2. Final value
  3. Number of all values in the vector
Answer from Eenoku on Stack Overflow
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.linspace.html
numpy.linspace — NumPy v2.4 Manual
>>> import matplotlib.pyplot as plt >>> N = 8 >>> y = np.zeros(N) >>> x1 = np.linspace(0, 10, N, endpoint=True) >>> x2 = np.linspace(0, 10, N, endpoint=False) >>> plt.plot(x1, y, 'o') [<matplotlib.lines.Line2D object at 0x...>] >>> plt.plot(x2, y + 0.5, 'o') [<matplotlib.lines.Line2D object at 0x...>] >>> plt.ylim([-0.5, 1]) (-0.5, 1) >>> plt.show()
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.linspace.html
numpy.linspace — NumPy v2.5.dev0 Manual
>>> import matplotlib.pyplot as plt >>> N = 8 >>> y = np.zeros(N) >>> x1 = np.linspace(0, 10, N, endpoint=True) >>> x2 = np.linspace(0, 10, N, endpoint=False) >>> plt.plot(x1, y, 'o') [<matplotlib.lines.Line2D object at 0x...>] >>> plt.plot(x2, y + 0.5, 'o') [<matplotlib.lines.Line2D object at 0x...>] >>> plt.ylim([-0.5, 1]) (-0.5, 1) >>> plt.show()
🌐
Note.nkmk.me
note.nkmk.me › home › python › numpy
NumPy: arange() and linspace() to generate evenly spaced values | note.nkmk.me
February 2, 2024 - In NumPy, the np.arange() and np.linspace() functions generate an array (ndarray) of evenly spaced values. You can specify the interval in np.arange() and the number of values in np.linspace(). numpy. ...
🌐
MathWorks
mathworks.com › matlabcentral › answers › 165615-create-equally-spaced-2-d-array
Create equally spaced 2-d array - MATLAB Answers - MATLAB Central
December 5, 2014 - Your code is correct, you've just mistaken in the line [arrayName(k,:) = linspace(0,k*2*pi, 100*k )], you should write 100*n instead of 100*k
🌐
Real Python
realpython.com › np-linspace-numpy
np.linspace(): Create Evenly or Non-Evenly Spaced Arrays – Real Python
December 1, 2023 - In this tutorial, you'll learn how to use NumPy's np.linspace() effectively to create an evenly or non-evenly spaced range of numbers. You'll explore several practical examples of the function's many uses in numerical applications.
🌐
DataCamp
datacamp.com › tutorial › how-to-use-the-numpy-linspace-function
How to Use the NumPy linspace() Function | DataCamp
April 5, 2024 - If you’re in a hurry, here’s the quickest explanation of the linspace() function. NumPy's linspace() function generates an array of evenly spaced numbers over a defined interval. Here, for example, we create an array that starts at 0 and ends at 100, throughout an interval of 5 numbers.
🌐
GeeksforGeeks
geeksforgeeks.org › python › numpy-linspace
NumPy linspace() Method | Create Evenly Spaced Array - GeeksforGeeks
February 14, 2026 - np.linspace(0, 1, num=25) generates 25 evenly spaced values between 0 and 1. .reshape(5, 5) converts the 1D array into a 2D array with 5 rows and 5 columns. Comment · Article Tags: Article Tags: Misc · Python · Python-numpy · Python numpy-arrayCreation ·
Find elsewhere
🌐
Medium
heartbeat.comet.ml › exploring-numpys-linspace-function-bb3378f8dcd8
Exploring NumPy’s linspace() function | by Ahmed Gad | Heartbeat
September 28, 2021 - You can think of the 1D array we created above as a 2D array in which the size of the first dimension is 5 but the size of the second dimension is just 1, and thus the array size is 5x1. In this section, we’ll increase the size of the second dimension. import numpy as np arr_1D = np.linspace(start=1, stop=5, num=5) print(arr_1D) print("Array Shape =", arr_1D.shape)[1.
🌐
MathWorks
mathworks.com › matlabcentral › fileexchange › 22824-linearly-spaced-multidimensional-matrix-without-loop
Linearly spaced multidimensional matrix without loop - File Exchange - MATLAB Central
May 19, 2014 - LINSPACENDIM(d1, d2) generates a multi-dimensional matrix of 100 linearly equally spaced points between each element of matrices d1 and d2.
Top answer
1 of 3
4
CopyIn [4]: xstep = np.linspace(0, 1, 2)

In [5]: ystep = np.linspace(0, 1, 3)

In [6]: xstep[:, None] + 1j*ystep
Out[6]: 
array([[0.+0.j , 0.+0.5j, 0.+1.j ],
       [1.+0.j , 1.+0.5j, 1.+1.j ]])

xstep[:, None] is equivalent to xstep[:, np.newaxis] and its purpose is to add a new axis to xstep on the right. Thus, xstep[:, None] is a 2D array of shape (2, 1).

CopyIn [19]: xstep[:, None].shape
Out[19]: (2, 1)

xstep[:, None] + 1j*ystep is thus the sum of a 2D array of shape (2, 1) and a 1D array of shape (3,).

NumPy broadcasting resolves this apparent shape conflict by automatically adding new axes (of length 1) on the left. So, by NumPy broadcasting rules, 1j*ystep is promoted to an array of shape (1, 3). (Notice that xstep[:, None] is required to explicitly add new axes on the right, but broadcasting will automatically add axes on the left. This is why 1j*ystep[None, :] was unnecessary though valid.)

Broadcasting further promotes both arrays to the common shape (2, 3) (but in a memory-efficient way, without copying the data). The values along the axes of length 1 are broadcasted repeatedly:

CopyIn [15]: X, Y = np.broadcast_arrays(xstep[:, None], 1j*ystep)

In [16]: X
Out[16]: 
array([[0., 0., 0.],
       [1., 1., 1.]])

In [17]: Y
Out[17]: 
array([[0.+0.j , 0.+0.5j, 0.+1.j ],
       [0.+0.j , 0.+0.5j, 0.+1.j ]])
2 of 3
3

You can use np.ogrid with imaginary "step" to obtain linspace semantics:

Copyy, x = np.ogrid[0:1:2j, 0:1:3j]                                                                               
y + 1j*x
# array([[0.+0.j , 0.+0.5j, 0.+1.j ],                                                                                 
#        [1.+0.j , 1.+0.5j, 1.+1.j ]])                                                                                

Here the ogrid line means make an open 2D grid. axis 0: 0 to 1, 2 steps, axis 1: 0 to 1, 3 steps. The type of the slice "step" acts as a switch, if it is imaginary (in fact anything of complex type) its absolute value is taken and the expression is treated like a linspace. Otherwise range semantics apply.

The return values

Copyy, x
# (array([[0.],                                                                                                       
#         [1.]]), array([[0. , 0.5, 1. ]]))                                                                                                                                                                                          

are "broadcast ready", so in the example we can simply add them and obtain a full 2D grid.

If we allow ourselves an imaginary "stop" parameter in the second slice (which only works with linspace semantics, so depending on your style you may prefer to avoid it) this can be condensed to one line:

Copysum(np.ogrid[0:1:2j, 0:1j:3j])
# array([[0.+0.j , 0.+0.5j, 0.+1.j ],
#        [1.+0.j , 1.+0.5j, 1.+1.j ]])

A similar but potentially more performant method would be preallocation and then broadcasting:

Copyout = np.empty((y.size, x.size), complex)
out.real[...], out.imag[...] = y, x
out
# array([[0.+0.j , 0.+0.5j, 0.+1.j ],
#        [1.+0.j , 1.+0.5j, 1.+1.j ]])

And another one using outer sum:

Copynp.add.outer(np.linspace(0,1,2), np.linspace(0,1j,3))
# array([[0.+0.j , 0.+0.5j, 0.+1.j ],
#        [1.+0.j , 1.+0.5j, 1.+1.j ]])
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.linspace.html
numpy.linspace — NumPy v2.1 Manual
>>> import matplotlib.pyplot as plt >>> N = 8 >>> y = np.zeros(N) >>> x1 = np.linspace(0, 10, N, endpoint=True) >>> x2 = np.linspace(0, 10, N, endpoint=False) >>> plt.plot(x1, y, 'o') [<matplotlib.lines.Line2D object at 0x...>] >>> plt.plot(x2, y + 0.5, 'o') [<matplotlib.lines.Line2D object at 0x...>] >>> plt.ylim([-0.5, 1]) (-0.5, 1) >>> plt.show()
🌐
MathWorks
mathworks.com › matlabcentral › answers › 1750320-creating-a-2d-grid-with-evenly-spaced-points
Creating a 2D grid with evenly spaced points - MATLAB Answers - MATLAB Central
June 29, 2022 - https://www.mathworks.com/matlabcentral/answers/1750320-creating-a-2d-grid-with-evenly-spaced-points#comment_2241555 · Cancel Copy to Clipboard · x = linspace(0,1,10) ; y = linspace(0,1,10) ; [X,Y] = meshgrid(x,y) ; P = [X(:) Y(:)] ; Sign in to comment. Sign in to answer this question.
🌐
Amazon S3
s3.amazonaws.com › assets.datacamp.com › production › course_2493 › slides › ch2_slides.pdf pdf
Working with 2D arrays INTRODUCTION TO DATA VISUALIZATION IN PYTHON
2D arrays & functions · INTRODUCTION TO DATA VISUALIZATION IN PYTHON · Using meshgrid() meshgrids.py : import numpy as np · u = np.linspace(-2, 2, 3) v = np.linspace(-1, 1, 5) X,Y = np.meshgrid(u, v) X : [[-2. 0. 2.] [-2. 0. 2.] [-2. 0. 2.] [-2. 0. 2.] [-2. 0.
🌐
Python Guides
pythonguides.com › python-numpy-linspace
NumPy's Linspace Function In Python
May 16, 2025 - Learn how to use NumPy's linspace function to create evenly spaced arrays in Python. Examples for data visualization, signal processing, and scientific computing
🌐
Fritz ai
heartbeat.fritz.ai › home › blog › exploring numpy’s linspace() function
Exploring NumPy’s linspace() function - Fritz ai
September 15, 2023 - What is np.linspace()? Function Arguments (start, stop, num) Create 1D Arrays · Possible Values for the num Argument · Use case: Plot Sine Wave using Matplotlib · Inclusive Range using endpoint Argument · Return Step using retstep Argument · Return Data Type using dtype Argument · Incremental and Decremental Ranges · Create 2D Arrays ·
🌐
Enterprise DNA
blog.enterprisedna.co › numpy-linspace
Numpy.linspace() in Python: A Guide To Create Arrays – Master Data Skills + AI
Additionally, np.linspace includes the endpoint by default, while np.arange does not. To generate a 2D array using numpy.linspace, you can combine it with the numpy.meshgrid function.