search
Search
Map of Data Science
search toc
Thanks for the thanks!
close
Cancel
Post
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

# NumPy | linspace method

schedule Mar 5, 2023
Last updated
local_offer
PythonNumPy
Tags
expand_more
map
Check out the interactive map of data science

Numpy's `linspace(~)` method creates a Numpy array with values that are equally spaced. Unlike Numpy's `arange(~)` method which uses step sizes, `linspace(~)` uses sample size.

# Parameters

1. `start` | `number`

The starting value of the Numpy array.

2. `stop` | `number`

The ending value of the Numpy array. This is inclusive.

3. `num` | `int` | `optional`

The number of samples you want to generate. By default, `num=50`.

4. `endpoint` | `boolean` | `optional`

If set to `True`, then stop will be the last value of the Numpy array. By default, `endpoint=False`.

5. `dtype` | `string` or `type` | `optional`

The desired data type for the Numpy array. This overrides the default behaviour of using the same data-type as the source array.

# Return value

A Numpy array with equally spaced values.

# Examples

## Basic Usage

Starting from a value of 1, and ending with a value of 10, we want to generate a total of 4 samples. We do so as follows:

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

Notice how the end value (i.e. the second parameter) is inclusive.

## Excluding the endpoint

We set `endpoint=False`, like follows:

``` np.linspace(1,10,4, endpoint=False) array([1. , 3.25, 5.5 , 7.75]) ```

## Explicit typing

We set `dtype=float` to obtain a Numpy array of type float.

``` np.linspace(1, 10, 4, dtype=float) array([ 1., 4., 7., 10.]) ```
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!