search
Search
Unlock 100+ guides
search toc
close
Cancel
Post
account_circle
Profile
exit_to_app
Sign out
What does this mean?
Why is this true?
Give me some examples!
search
keyboard_voice
close
Searching Tips
Search for a recipe:
"Creating a table in MySQL"
Search for an API documentation: "@append"
Search for code: "!dataframe"
Apply a tag filter: "#python"
Useful Shortcuts
/ to open search panel
Esc to close search panel
to navigate between search results
d to clear all current filters
Enter to expand content preview
Doc Search
Code Search Beta
SORRY NOTHING FOUND!
mic
Start speaking...
Voice search is only supported in Safari and Chrome.
Shrink
Navigate to

# NumPy | arange method

schedule Aug 12, 2023
Last updated
local_offer
PythonNumPy
Tags
mode_heat
Master the mathematics behind data science with 100+ top-tier guides
Start your free 7-days trial now!

NumPy's `arange(~)` method is used to create a NumPy array with equally spaced values, similar to Python's `range(~)` method.

# Parameters

1. `start` | `number` | `optional`

The starting value. This will be the first element in the NumPy array.

2. `stop`link | `number`

The end value. Just like Python's `range(~)` method, the interval does not include this value.

3. `step`link | `number` | `optional`

Spacing between values. By default, `step=1`.

4. `dtype`link | `string` or `type` | `optional`

The desired data type for the NumPy array. By default, the type is inferred based on the other parameters.

# Return value

A NumPy array with equally spaced values.

# Examples

## Specifying only the end value

To obtain a NumPy array from 0 (inclusive) to 3 (exclusive):

``` np.arange(3) array([0, 1, 2]) ```

Notice how the value 3, which is the `stop` parameter, is excluded from the NumPy array.

## Specifying start and end value

To obtain a NumPy array from 2 (inclusive) to 5 (exclusive):

``` np.arange(start=2, stop=5) array([2, 3, 4]) ```

## Specifying step size

To obtain a NumPy array where the values are evenly spaced by 3 units:

``` np.arange(1, 10, 3) array([1, 4, 7]) ```

## Specifying a negative step size

``` np.arange(6, 2, -1) array([6, 5, 4, 3]) ```

## Specifying dtype

To create a NumPy array of floats starting from 2.0 (inclusive) and ending at 5 (exclusive):

``` np.arange(start=2, stop=5, dtype="float") array([2., 3., 4.]) ```
Edited by 0 others
thumb_up
thumb_down
Comment
Citation
Ask a question or leave a feedback...
thumb_up
0
thumb_down
0
chat_bubble_outline
0
settings
Enjoy our search
Hit / to insta-search docs and recipes!