# numpy.linspace() in Python

## numpy.linspace() in Python

The numpy.linspace() function returns number spaces evenly w.r.t interval. Similar to numpy.arrange() function but instead of step it uses sample number.
Syntax :

```numpy.linspace(start,
stop,
num = 50,
endpoint = True,
retstep = False,
dtype = None)```

Parameters :

```-> start  : [optional] start of interval range. By default start = 0
-> stop   : end of interval range
-> restep : If True, return (samples, step). By deflut restep = False
-> num    : [int, optional] No. of samples to generate
-> dtype  : type of output array```

Return :

```-> ndarray
-> step : [float, optional], if restep = True```

Code 1 : Explaining linspace function

 `# Python Programming illustrating` `# numpy.linspace method` `import` `numpy as geek` `# restep set to True` `print``(``"B\n"``, geek.linspace(``2.0``, ``3.0``, num``=``5``, retstep``=``True``), ``"\n"``)` `# To evaluate sin() in long range` `x ``=` `geek.linspace(``0``, ``2``, ``10``)` `print``(``"A\n"``, geek.sin(x))`

Output :

```B
(array([ 2.  ,  2.25,  2.5 ,  2.75,  3.  ]), 0.25)

A
[ 0.          0.22039774  0.42995636  0.6183698   0.77637192  0.8961922
0.9719379   0.99988386  0.9786557   0.90929743]```

Code 2 : Graphical Representation of numpy.linspace() using matplotlib module – pylab

 `# Graphical Representation of numpy.linspace()` `import` `numpy as geek` `import` `pylab as p` `# Start = 0` `# End = 2` `# Samples to generate = 10` `x1 ``=` `geek.linspace(``0``, ``2``, ``10``, endpoint ``=` `False``)` `y1 ``=` `geek.ones(``10``)` `p.plot(x1, y1, ``'*'``)` `p.xlim(``-``0.2``, ``1.8``)`

Output :

Code 3 : Graphical Representation of numpy.linspace() using pylab

 `# Graphical Representation of numpy.linspace()` `import` `numpy as geek` `import` `pylab as p` `# Start = 0` `# End = 2` `# Samples to generate = 15` `x1 ``=` `geek.linspace(``0``, ``2``, ``15``, endpoint ``=` `True``)` `y1 ``=` `geek.zeros(``15``)` `p.plot(x1, y1, ``'o'``)` `p.xlim(``-``0.2``, ``2.1``)`

Output :

Note :
These NumPy-Python programs won’t run on onlineID, so run them on your systems to explore them
.

Last Updated on November 13, 2021 by admin

## How to create a vector in Python using NumPyHow to create a vector in Python using NumPy

How to create a vector in Python using NumPy NumPy is a general-purpose array-processing package. It provides a high-performance multidimensional array object, and tools for working with these arrays. It is the fundamental package for scientific computing with Python. Numpy is

## numpy.log() in Pythonnumpy.log() in Python

numpy.log() in Python The numpy.log() is a mathematical function that helps user to calculate Natural logarithm of x where x belongs to all the input array elements. Natural logarithm log is the inverse of the exp(), so that log(exp(x)) = x. The natural logarithm is log

## Calculate the Euclidean distance using NumPyCalculate the Euclidean distance using NumPy

Calculate the Euclidean distance using NumPy In simple terms, Euclidean distance is the shortest between the 2 points irrespective of the dimensions. In this article to find the Euclidean distance, we will use the NumPy library. This library used for manipulating multidimensional

## numpy.percentile() in pythonnumpy.percentile() in python

numpy.percentile() in python numpy.percentile()function used to compute the nth percentile of the given data (array elements) along the specified axis. Syntax : numpy.percentile(arr, n, axis=None, out=None) Parameters : arr :input array. n : percentile value. axis : axis along which we want to

## Numpy size() function | PythonNumpy size() function | Python

Numpy size() function | Python In Python, numpy.size() function count the number of elements along a given axis. Syntax: numpy.size(arr, axis=None) Parameters: arr: [array_like] Input data. axis: [int, optional] Axis(x,y,z) along which the elements(rows or columns) are counted. By default, give the total

## How to select rows from a dataframe based on column values ?How to select rows from a dataframe based on column values ?

How to select rows from a dataframe based on column values ? The rows of a dataframe can be selected based on conditions as we do use the SQL queries. The various methods to achieve this is explained in this

## numpy.mean() in Pythonnumpy.mean() in Python

numpy.mean() in Python numpy.mean(arr, axis = None) : Compute the arithmetic mean (average) of the given data (array elements) along the specified axis. Parameters : arr : [array_like]input array. axis : [int or tuples of int]axis along which we want to calculate the arithmetic

## Convert a NumPy array to an imageConvert a NumPy array to an image

Convert a NumPy array to an image NumPy Or numeric python is a popular library for array manipulation. Since images are just an array of pixels carrying various color codes. NumPy can be used to convert an array into image. Apart from