Change language

numpy.linspace () in Python

|

About:
numpy.linspace (start, stop, num = 50, endpoint = True, retstep = False, dtype = None): returns numeric spaces evenly spaced. Similar to arange, but uses the sample number instead of the step. 
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: Explain linspace function

# Python Programming Illustrative
# numpy.linspace method

 

import numpy as geek

 
# restep set to True

print ( "B" , geek.linspace ( 2.0 , 3.0 , num = 5 , retstep = True ), "" )

 
# To evaluate sin () at a great distance

x = geek.linspace ( 0 , 2 , 10 )

print ( " A " , 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 a module matplotlib & # 8212; 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: Plotting 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 )

Exit:

Notes:
These NumPy-Python programs will not work by onlineID, so run them on your systems to learn them

This article is provided by Mohit Gupta_OMG

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers


Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method