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. ...
🌐
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.
🌐
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
🌐
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.
🌐
YouTube
youtube.com › scientific_math
2D Plotting in Matlab usnig linspace l simple function plotting l linspace command l How - YouTube
2D plotting in Matlab usnig linspace l simple function plotting l linspace command l How How to plot function in Matlab using linspace command (linearly spac...
Published   August 4, 2021
Views   995
Find elsewhere
🌐
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.
🌐
Problem Solving with Python
problemsolvingwithpython.com › 05-NumPy-and-Arrays › 05.04-Array-Creation
Array Creation - Problem Solving with Python
NumPy's np.linspace() function creates a NumPy array according the arguments start, stop,number of elements.
🌐
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 ·
🌐
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.
🌐
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
🌐
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()
🌐
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 ·
🌐
PyTorch
docs.pytorch.org › reference api › torch.linspace
torch.linspace — PyTorch 2.11 documentation
January 1, 2023 - >>> torch.linspace(3, 10, steps=5) tensor([ 3.0000, 4.7500, 6.5000, 8.2500, 10.0000]) >>> torch.linspace(-10, 10, steps=5) tensor([-10., -5., 0., 5., 10.]) >>> torch.linspace(start=-10, end=10, steps=5) tensor([-10., -5., 0., 5., 10.]) >>> torch.linspace(start=-10, end=10, steps=1) tensor([-10.])