search
Search
Guest 0reps
Thanks for the thanks!
close
account_circle
Profile
exit_to_app
Sign out
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
A
A
brightness_medium
share
arrow_backShare

# NumPy | arange method

Programming
chevron_right
Python
chevron_right
NumPy
chevron_right
Documentation
schedule Jul 1, 2022
Last updated
local_offer PythonNumPy
Tags

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.]) ```
mail
Edited by 0 others