numpy.linspace函數(shù)具體使用詳解
numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)
在指定的間隔內(nèi)返回均勻間隔的數(shù)字。
返回num均勻分布的樣本,在[start, stop]。
這個區(qū)間的端點可以任意的被排除在外。
| Parameters(參數(shù)): |
start : scalar(標(biāo)量)
stop : scalar
num : int, optional(可選)
endpoint : bool, optional
retstep : bool, optional
dtype : dtype, optional
|
|---|---|
| Returns: |
samples : ndarray
step : float(只有當(dāng)retstep設(shè)置為真的時候才會存在)
|
See also
arange
Similar to linspace, but uses a step size (instead of the number of samples)
.arange使用的是步長,而不是樣本的數(shù)量
logspace
Samples uniformly distributed in log space.
當(dāng)endpoint被設(shè)置為False的時候
>>> import numpy as np >>> np.linspace(1, 10, 10) array([ 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.]) >>> np.linspace(1, 10, 10, endpoint = False) array([ 1. , 1.9, 2.8, 3.7, 4.6, 5.5, 6.4, 7.3, 8.2, 9.1]) In [4]: np.linspace(1, 10, 10, endpoint = False, retstep= True) Out[4]: (array([ 1. , 1.9, 2.8, 3.7, 4.6, 5.5, 6.4, 7.3, 8.2, 9.1]), 0.9)
官網(wǎng)的例子
Examples
>>> >>> np.linspace(2.0, 3.0, num=5) array([ 2. , 2.25, 2.5 , 2.75, 3. ]) >>> np.linspace(2.0, 3.0, num=5, endpoint=False) array([ 2. , 2.2, 2.4, 2.6, 2.8]) >>> np.linspace(2.0, 3.0, num=5, retstep=True) (array([ 2. , 2.25, 2.5 , 2.75, 3. ]), 0.25)
Graphical illustration:
>>> >>> import matplotlib.pyplot as plt >>> N = 8 >>> y = np.zeros(N) >>> x1 = np.linspace(0, 10, N, endpoint=True) >>> x2 = np.linspace(0, 10, N, endpoint=False) >>> plt.plot(x1, y, 'o') [<matplotlib.lines.Line2D object at 0x...>] >>> plt.plot(x2, y + 0.5, 'o') [<matplotlib.lines.Line2D object at 0x...>] >>> plt.ylim([-0.5, 1]) (-0.5, 1) >>> plt.show()

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
在python win系統(tǒng)下 打開TXT文件的實例
下面小編就為大家分享一篇在python win系統(tǒng)下 打開TXT文件的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-04-04
centos+nginx+uwsgi+Django實現(xiàn)IP+port訪問服務(wù)器
這篇文章主要介紹了centos+nginx+uwsgi+Django實現(xiàn)IP+port訪問服務(wù)器,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11
Python xlwt設(shè)置excel單元格字體及格式
這篇文章主要為大家詳細(xì)介紹了Python xlwt設(shè)置excel單元格字體及格式的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-12-12

