I recommend that you work through a tutorial on for loops -- the information you need is there, as well as other hints on using controlled iteration. To solve your immediate need, simply increase your upper bound by one loop increment:

inc = 2*np.pi/360
theta = np.arange(0, angle/2 + inc, inc)
Answer from Prune on Stack Overflow
🌐
Statology
statology.org › home › numpy: how to use arange and include endpoint
NumPy: How to Use arange and Include Endpoint
March 20, 2023 - This tutorial explains how to use the NumPy arange function and include the endpoint as a value in the array, including examples.
🌐
Arab Psychology
scales.arabpsychology.com › home › how to include the endpoint in your numpy arange sequence
How To Include The Endpoint In Your Numpy Arange Sequence
November 20, 2025 - We effectively tell arange to generate values up to 55 (exclusive), which guarantees that 50 is included in the iteration process: import numpy as np #specify start, stop, and step size start = 0 stop = 50 step = 5 #create array, ensuring endpoint inclusion np.arange(start, stop + step, step) array([ 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50])
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.arange.html
numpy.arange — NumPy v2.1 Manual
>>> power = 40 >>> modulo = 10000 >>> x1 = [(n ** power) % modulo for n in range(8)] >>> x2 = [(n ** power) % modulo for n in np.arange(8)] >>> print(x1) [0, 1, 7776, 8801, 6176, 625, 6576, 4001] # correct >>> print(x2) [0, 1, 7776, 7185, 0, 5969, 4816, 3361] # incorrect ... Evenly spaced numbers with careful handling of endpoints.
🌐
Python Pool
pythonpool.com › home › blog › the numpy arange function and including endpoints
The Numpy arange Function and Including Endpoints - Python Pool
July 20, 2022 - NumPy arange() does not include the endpoint. However, the MatLab equivalent does have an endpoint.
🌐
Note.nkmk.me
note.nkmk.me › home › python › numpy
NumPy: arange() and linspace() to generate evenly spaced values | note.nkmk.me
February 2, 2024 - numpy.linspace — NumPy v1.26 Manual · Contents · How to use np.arange() How to use np.linspace() Basic usage · Specify whether to include stop: endpoint · Get the interval: retstep · Convert to reverse order · Convert to multi-dimensional arrays · The NumPy version used in this article is as follows.
🌐
NumPy
numpy.org › doc › 2.2 › user › how-to-partition.html
How to create arrays with regularly-spaced values — NumPy v2.2 Manual
Floating-point inaccuracies can make arange results with floating-point numbers confusing. In this case, you should use numpy.linspace instead. Use numpy.linspace if you want the endpoint to be included in the result, or if you are using a non-integer step size.
🌐
DataCamp
datacamp.com › doc › numpy › arange
NumPy arange()
If you need a specific number of elements instead of a specific step size, consider using numpy.linspace(). Specify dtype for clarity. When necessary, explicitly define the dtype to ensure the array has the desired data type. Check array length. Verify the length if using non-integer steps, as the result may not include the endpoint.
Find elsewhere
🌐
NumPy
numpy.org › doc › stable › user › how-to-partition.html
How to create arrays with regularly-spaced values — NumPy v2.4 Manual
Floating-point inaccuracies can make arange results with floating-point numbers confusing. In this case, you should use numpy.linspace instead. Use numpy.linspace if you want the endpoint to be included in the result, or if you are using a non-integer step size.
🌐
Stack Abuse
stackabuse.com › guide-to-numpys-arange-function
Guide to NumPy's arange() Function
May 8, 2023 - For a list of all supported NumPy ... specify the number of samples in a certain range instead of specifying the step. In addition, you can include endpoints in the returned array....
🌐
GeeksforGeeks
geeksforgeeks.org › python › numpy-arrange-in-python
numpy.arange() in Python - GeeksforGeeks
February 14, 2026 - Default is 0. stop: The endpoint of the sequence, exclusive. step (optional): The spacing between consecutive values. Default is 1. dtype (optional): The desired data type of the output array.
🌐
GitHub
github.com › numpy › numpy › issues › 11913
numpy arange includes right hand side · Issue #11913 · numpy/numpy
September 8, 2018 - numpy arange includes right hand side#11913 · Copy link · rshap91 · opened · on Sep 8, 2018 · Issue body actions · Not sure if this is a bug or not but i seem to be able to generate an array using np.arange that includes the right hand side... import numpy as np np.arange(1,1.5,.1) # array([1.
Author   rshap91
🌐
NumPy
numpy.org › doc › 2.1 › user › how-to-partition.html
How to create arrays with regularly-spaced values — NumPy v2.1 Manual
numpy.arange relies on step size to determine how many elements are in the returned array, which excludes the endpoint.
🌐
Real Python
realpython.com › how-to-use-numpy-arange
NumPy arange(): How to Use np.arange() – Real Python
July 31, 2023 - In addition to arange(), you can ... in that it returns evenly spaced numbers. But you can specify the number of values to generate as well as whether to include the endpoint and whether to create ......
🌐
pythontutorials
pythontutorials.net › blog › numpy-arange-include-endpoint
Mastering `numpy.arange` with Endpoint Control — pythontutorials.net
import numpy as np # Create an array from 0 to 4 (endpoint excluded) arr = np.arange(5) print(arr) As mentioned earlier, by default, the stop value is excluded. If you want to include the endpoint, you can make a small adjustment to the stop value.
Top answer
1 of 7
19

A simpler approach to get the desired output is to add the step size in the upper limit. For instance,

np.arange(start, end + step, step)

would allow you to include the end point as well. In your case:

np.arange(0.0, 0.6 + 0.2, 0.2)

would result in

array([0. , 0.2, 0.4, 0.6]).
2 of 7
14

Update 2023-04-21

Had a bug in the code for stop - start being a non-integer number of steps => fixed

In short / TLDR

unexpected behavior:

>>> np.arange(1, 1.3, .1)  # UNEXPECTED
array([1. , 1.1, 1.2, 1.3])

fix:

>>> from arange_cust import *
>>> np_arange_closed(1, 1.3, .1)
array([1. , 1.1, 1.2, 1.3])
>>> np_arange_open(1, 1.3, .1)
array([1. , 1.1, 1.2])

Background information

I had your problem a few times as well. I usually quick-fixed it with adding a small value to stop. As mentioned by Kasrâmvd in the comments, the issue is a bit more complex, as floating point rounding errors can occur in numpy.arange (see here and here).

Unexpected behavior can be found in this example:

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

To clear up things a bit for myself, I decided to be very careful with np.arange.

Code

arange_cust.py:

import numpy as np

def np_arange_cust(
        *args, rtol: float=1e-05, atol: float=1e-08, include_start: bool=True, include_stop: bool = False, **kwargs
):
    """
    Combines numpy.arange and numpy.isclose to mimic open, half-open and closed intervals.

    Avoids also floating point rounding errors as with
    >>> np.arange(1, 1.3, 0.1)
    array([1., 1.1, 1.2, 1.3])

    Parameters
    ----------
    *args : float
        passed to np.arange
    rtol : float
        if last element of array is within this relative tolerance to stop and include[0]==False, it is skipped
    atol : float
        if last element of array is within this relative tolerance to stop and include[1]==False, it is skipped
    include_start: bool
        if first element is included in the returned array
    include_stop: bool
        if last elements are included in the returned array if stop equals last element
    kwargs :
        passed to np.arange

    Returns
    -------
    np.ndarray :
        as np.arange but eventually with first and last element stripped/added
    """
    # process arguments
    if len(args) == 1:
        start = 0
        stop = args[0]
        step = 1
    elif len(args) == 2:
        start, stop = args
        step = 1
    else:
        assert len(args) == 3
        start, stop, step = tuple(args)

    arr = np.arange(start, stop, step, **kwargs)
    if not include_start:
        arr = np.delete(arr, 0)

    if include_stop:
        if np.isclose(arr[-1] + step, stop, rtol=rtol, atol=atol):
            arr = np.c_[arr, arr[-1] + step]
    else:
        if np.isclose(arr[-1], stop, rtol=rtol, atol=atol):
            arr = np.delete(arr, -1)
    return arr

def np_arange_closed(*args, **kwargs):
    return np_arange_cust(*args, **kwargs, include_start=True, include_stop=True)

def np_arange_open(*args, **kwargs):
    return np_arange_cust(*args, **kwargs, include_start=True, include_stop=False)

Pytests

To avoid bugs in future, here is a testing module. In case we find something again, lets add a testcase. test_arange_cust.py:

import numpy as np
from arange_cust import np_arange_cust, np_arange_closed, np_arange_open
import pytest

class Test_np_arange_cust:
    paras_minimal_working_example = {
        "arange simple": {
            "start": 0, "stop": 7, "step": 1, "include_start": True, "include_stop": False,
            "res_exp": np.array([0, 1, 2, 3, 4, 5, 6])
        },
        "stop not on grid": {
            "start": 0, "stop": 6.5, "step": 1, "include_start": True, "include_stop": False,
            "res_exp": np.array([0, 1, 2, 3, 4, 5, 6])
        },
        "arange failing example: stop excl": {
            "start": 1, "stop": 1.3, "step": .1, "include_start": True, "include_stop": False,
            "res_exp": np.array([1., 1.1, 1.2])
        },
        "arange failing example: stop incl": {
            "start": 1, "stop": 1.3, "step": .1, "include_start": True, "include_stop": True,
            "res_exp": np.array([1., 1.1, 1.2, 1.3])
        },
        "arange failing example: stop excl + start excl": {
            "start": 1, "stop": 1.3, "step": .1, "include_start": False, "include_stop": False,
            "res_exp": np.array([1.1, 1.2])
        },
        "arange failing example: stop incl + start excl": {
            "start": 1, "stop": 1.3, "step": .1, "include_start": False, "include_stop": True,
            "res_exp": np.array([1.1, 1.2, 1.3])
        },

    }

    @pytest.mark.parametrize(
        argnames=next(iter(paras_minimal_working_example.values())).keys(),
        argvalues=[tuple(paras.values()) for paras in paras_minimal_working_example.values()],
        ids=paras_minimal_working_example.keys(),
    )
    def test_minimal_working_example(self, start, stop, step, include_start, include_stop, res_exp):
        res = np_arange_cust(start, stop, step, include_start=include_start, include_stop=include_stop)
        assert np.allclose(res, res_exp), f"Unexpected result: {res=}, {res_exp=}"
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.arange.html
numpy.arange — NumPy v2.4 Manual
>>> power = 40 >>> modulo = 10000 >>> x1 = [(n ** power) % modulo for n in range(8)] >>> x2 = [(n ** power) % modulo for n in np.arange(8)] >>> print(x1) [0, 1, 7776, 8801, 6176, 625, 6576, 4001] # correct >>> print(x2) [0, 1, 7776, 7185, 0, 5969, 4816, 3361] # incorrect ... Evenly spaced numbers with careful handling of endpoints.
🌐
Arab Psychology
scales.arabpsychology.com › home › stats › how can i use numpy’s arange function to create an array that includes the endpoint?
How Can I Use NumPy's Arange Function To Create An Array That Includes The Endpoint?
June 24, 2024 - It allows you to specify the start, stop, and step size of the array. By default, the endpoint is not included in the array. However, if you want to include the endpoint, you can simply add 1 to the stop value.
🌐
Codegive
codegive.com › blog › numpy_arange_with_endpoint.php
Numpy arange with endpoint
Output: NumPy array. Data Types: Primarily float. Endpoint: stop is inclusive by default. Control: Similar to np.linspace, but generates numbers evenly spaced on a logarithmic scale. Use Case: Useful for creating scales for frequency analysis, decibel scales, etc.
🌐
AskPython
askpython.com › home › numpy arange() method in python
NumPy arange() method in Python - AskPython
January 25, 2026 - Use np.arange() when you know the step size and endpoint inclusion would cause issues. Floating point precision creates the most frequent issues with np.arange(). The internal implementation calculates steps as dtype(start + step) - dtype(start), which can lose precision when start significantly exceeds step. import numpy as np # Unexpected behavior with float dtype conversion arr1 = np.arange(0, 5, 0.5, dtype=int) print(arr1) # Output: [0 0 0 0 0 0 0 0 0 0] # Unexpected!