np.linspace allows you to define how many values you get including the specified min and max value. It infers the stepsize:

>>> np.linspace(0,1,11)
array([0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. ])

np.arange allows you to define the stepsize and infers the number of steps(the number of values you get).

>>> np.arange(0,1,.1)
array([0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9])

contributions from user2357112:

np.arange excludes the maximum value unless rounding error makes it do otherwise.

For example, the following results occur due to rounding error:

>>> numpy.arange(1, 1.3, 0.1)
array([1. , 1.1, 1.2, 1.3])

You can exclude the stop value (in our case 1.3) using endpoint=False:

>>> numpy.linspace(1, 1.3, 3, endpoint=False)
array([1. , 1.1, 1.2])
Answer from warped on Stack Overflow
๐ŸŒ
Statology
statology.org โ€บ home โ€บ numpy: the difference between np.linspace and np.arange
NumPy: The Difference Between np.linspace and np.arange
July 21, 2022 - linspace allows you to specify the number of steps ยท arange allows you to specify the size of the steps ยท The following examples show how to use each function in practice. The np.linspace() function uses the following basic syntax:
Discussions

linear algebra - How to express the Pythons' NumPy linspace or arange arrays mathematically? - Mathematics Stack Exchange
To be more specific, say one have the range expressed as x = np.arange(-1, 1, 0.1), which gives: More on math.stackexchange.com
๐ŸŒ math.stackexchange.com
January 5, 2015
Numpy.arange() decimal precision
It's floating point error . More on reddit.com
๐ŸŒ r/learnpython
6
2
March 21, 2020
How to make a list or array of numbers covering a wide range [1e-6,1e-5...1e6]?
The other answer is likely all you need, but for good measure, you could use a list comprehension: [ 1 ** x for x in range(-6, 6) ] Output would be something like this (from memory): [1e-6, 1e-5, 1e-4, โ€ฆ , 1e4, 1e5] Of course, you could wrap the list in np.array to produce an array if needed. More on reddit.com
๐ŸŒ r/learnpython
4
2
December 20, 2022
Difference between range and arange?

numpy.arange

numpy.arange([start, ]stop, [step, ]dtype=None)

Return evenly spaced values within a given interval.

Values are generated within the half-open interval [start, stop) (in other words, the interval including start but excluding stop). For integer arguments the function is equivalent to the Python built-in range function, but returns an ndarray rather than a list.

(Source)

So they are the same when using integers (except for the return type), but numpy's version can use other variable types.

If you're using Python 3, though, note that range has changed and now returns an iterator instead of a list. (Explained here.)

More on reddit.com
๐ŸŒ r/learnpython
2
10
August 6, 2015
๐ŸŒ
The Python Coding Stack
thepythoncodingstack.com โ€บ p โ€บ difference-between-numpy-arange-and-linspace
What's The Difference Between NumPy's `arange()` and `linspace()` (A NumPy for Numpties article)
July 18, 2024 - You use a start, stop and step value when you use arange(). It's up to you to decide the step size. But beware of odd results when using float step sizes or casting into specific data types.
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ stable โ€บ user โ€บ how-to-partition.html
How to create arrays with regularly-spaced values โ€” NumPy v2.4 Manual
>>> np.arange(0, 10, 2) # np.arange(start, stop, step) array([0, 2, 4, 6, 8]) The arguments start and stop should be integer or real, but not complex numbers. numpy.arange is similar to the Python built-in range. Floating-point inaccuracies can make arange results with floating-point numbers confusing. In this case, you should use numpy.linspace instead.
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python โ€บ numpy
arange() and linspace() to generate evenly spaced values
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.arange โ€” NumPy v1.26 Manual ยท numpy.linspace โ€” NumPy v1.26 Manual ยท
๐ŸŒ
Quora
quora.com โ€บ What-is-difference-between-arange-and-linspace-functions-of-NumPy
What is difference between arange() and linspace() functions of NumPy? - Quora
arange(start, stop, step): spacing is given explicitly by step. The sequence includes values start, start+step, ... up to but not including stop (stop is a strict upper bound for positive step). linspace(start, stop, num): number of samples ...
Find elsewhere
๐ŸŒ
Plain English
python.plainenglish.io โ€บ title-numpy-linspace-vs-arange-which-to-choose-for-evenly-spaced-sequences-7ffb36ad98ca
Title: โ€œNumPy: linspace vs arange: Which to Choose for Evenly Spaced Sequences?โ€
November 24, 2023 - But hereโ€™s the twist: `np.linspace` creates values with the start and end points included, while `np.arange` leaves you hanging right before the end point.
๐ŸŒ
Oreate AI
oreateai.com โ€บ blog โ€บ nplinspace-vs-nparange-choosing-the-right-tool-for-your-number-sequences โ€บ 15722ca9f5ddf420e3a78a94056d18df
np.linspace vs. np.arange: Choosing the Right Tool for Your Number Sequences - Oreate AI Blog
January 23, 2026 - It's not about one being 'better' than the other, but rather understanding their strengths. arange is great for simple, integer-based steps, while linspace offers more robust control and precision, especially when floating-point numbers are ...
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 2.3 โ€บ user โ€บ how-to-partition.html
How to create arrays with regularly-spaced values โ€” NumPy v2.3 Manual
>>> np.arange(0, 10, 2) # np.arange(start, stop, step) array([0, 2, 4, 6, 8]) The arguments start and stop should be integer or real, but not complex numbers. numpy.arange is similar to the Python built-in range. Floating-point inaccuracies can make arange results with floating-point numbers confusing. In this case, you should use numpy.linspace instead.
๐ŸŒ
IncludeHelp
includehelp.com โ€บ python โ€บ what-is-the-difference-between-np-linspace-and-np-arange-methods.aspx
Python - What is the difference between np.linspace() and ...
February 14, 2023 - The numpy.arange() returns evenly spaced values within a given interval. Values are generated within the half-open interval [start, stop) (in other words, the interval includes the start but excludes the stop). For integer arguments, the function is equivalent to the Python built-in range function ...
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ numpy โ€บ numpy_array_reshape.asp
NumPy Array Reshaping
import numpy as np arr = np.array([1, 2, 3, 4, 5, 6, 7, 8]) newarr = arr.reshape(3, 3) print(newarr) Try it Yourself ยป
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ numpy.arange() decimal precision
r/learnpython on Reddit: Numpy.arange() decimal precision
March 21, 2020 -

Hello, I am fairly new to python and have been using it for homework and school projects as of late. However, I have been noticing a trend when I am attempting to use numpy's arrange feature for creating lists. I can create the list and print it to the command window in spyder and everything seems fine, but when I go to use the elements of the list, extra decimals seemed to be added to the end of some of the elements.

This is what I expect to happen in Spyder

import numpy as np
X=np.arange(0,1.1,0.1)
print(X)
>>[0.  0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1. ]

But when I use this list for naming (File names, plot titles, and legends) I get extra decimals such as 0.30000000000000004

Which is really confusing me. I figured out that I can use the round function in python and just round the numbers off to rid of the extra decimals, but this is becoming very tedious and isn't what I would expect.

Is there something I am doing wrong or is this just an innate feature of numpy.arange()? Any comments or tips are appreciated!

๐ŸŒ
GitHub
bic-berkeley.github.io โ€บ psych-214-fall-2016 โ€บ arange.html
Numpy arange โ€” Functional MRI methods
Because arange returns arrays, you can use NumPy element-wise operations to multiply by the step size and add a start value. This is one way to create equally spaced vectors (np.linspace is another):
๐ŸŒ
NumPy
numpy.org โ€บ devdocs โ€บ reference โ€บ generated โ€บ numpy.linspace.html
numpy.linspace โ€” NumPy v2.5.dev0 Manual
arange ยท Similar to linspace, but uses a step size (instead of the number of samples). geomspace ยท Similar to linspace, but with numbers spaced evenly on a log scale (a geometric progression). logspace ยท Similar to geomspace, but with the end points specified as logarithms.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ numpy โ€บ default.asp
NumPy Tutorial
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
๐ŸŒ
GitConnected
levelup.gitconnected.com โ€บ linspace-vs-arange-numpy-quick-comparison-f88081263e5a
Linspace vs. Arange (NumPy) Quick Comparison | by Adam Ross Nelson | Level Up Coding
November 20, 2023 - import numpy as np # np.arange; numbers from 0 to 100 (exclusive), step of 10 arange_vals_1 = np.arange(0, 100, 10) print("np.arange(0, 100, 10):", arange_vals_1) # np.linspace; 10 evenly spaced numbers from 0 to 90 (inclusive) linspace_vals_1 = np.linspace(0, 90, 10) print("np.linspace(0, 90, 10):", linspace_vals_1) # np.arange; numbers from 0 to 100 (exclusive), step of 5 arange_vals_2 = np.arange(0, 100, 5) print("np.arange(0, 100, 5):", arange_vals_2) # np.linspace; 5 evenly spaced numbers from 0 to 100 (inclusive) linspace_vals_2 = np.linspace(0, 100, 5) print("np.linspace(0, 100, 5):", linspace_vals_2)
๐ŸŒ
Medium
medium.com โ€บ @24littledino โ€บ range-python-vs-arange-numpy-3dc2953b9467
Range(Python) vs. Arange(NumPy). Introduction | by Little Dino | Medium
March 5, 2022 - The range function can only generate integer values. However, for arange function, you can assign the data type by specifying dtype parameter (e.g., np.arange(start=0.2, stop=0.5, step=0.1, dtype=float) will generate a NumPy array, array([0.2, 0.3, 0.4]).)