欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python numpy庫linspace相同間隔采樣的實現(xiàn)

 更新時間:2020年02月25日 10:46:28   作者:brucewong0516  
這篇文章主要介紹了python numpy庫linspace相同間隔采樣的實現(xiàn),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

linspace可以用來實現(xiàn)相同間隔的采樣;

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

返回num均勻分布的樣本,在[start, stop]。

Parameters(參數(shù)):

start : scalar(標量) The starting value of the sequence(序列的起始點).

stop : scalar 序列的結(jié)束點,除非endpoint被設(shè)置為False,在這種情況下, the sequence consists of all but the last of num + 1 evenly spaced samples(該序列包括所有除了最后的num+1上均勻分布的樣本(感覺這樣翻譯有點坑)), 以致于stop被排除.當endpoint is False的時候注意步長的大小(下面有例子).

num : int, optional(可選), 生成的樣本數(shù),默認是50。必須是非負。

endpoint : bool, optional, 如果是真,則一定包括stop,如果為False,一定不會有stop

retstep : bool, optional If True, return (samples, step), where step is the spacing between

samples.(看例子)

dtype : dtype, optional The type of the output array. If dtype is not given, infer the data type from the other input arguments(推斷這個輸入用例從其他的輸入中). New in version 1.9.0.

Returns:

samples : ndarray
There are num equally spaced samples in the closed
interval [start, stop] or the half-open
interval [start, stop) (depending on whether endpoint is True or False).

step : float(只有當retstep設(shè)置為真的時候才會存在)
Only returned if retstep is True
Size of spacing between samples.

當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()

以上這篇python numpy庫linspace相同間隔采樣的實現(xiàn)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Python動態(tài)創(chuàng)建類實例詳解

    Python動態(tài)創(chuàng)建類實例詳解

    這篇文章主要為大家介紹了Python動態(tài)創(chuàng)建類實例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-12-12
  • Pycharm在創(chuàng)建py文件時,自動添加文件頭注釋的實例

    Pycharm在創(chuàng)建py文件時,自動添加文件頭注釋的實例

    今天小編就為大家分享一篇Pycharm在創(chuàng)建py文件時,自動添加文件頭注釋的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-05-05
  • 使用Python的Turtle繪制哆啦A夢實例

    使用Python的Turtle繪制哆啦A夢實例

    今天小編就為大家分享一篇使用Python的Turtle繪制哆啦A夢實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-11-11
  • python實現(xiàn)XML解析的方法解析

    python實現(xiàn)XML解析的方法解析

    這篇文章主要介紹了python實現(xiàn)XML解析的方法解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2019-11-11
  • python實現(xiàn)銀行實戰(zhàn)系統(tǒng)

    python實現(xiàn)銀行實戰(zhàn)系統(tǒng)

    這篇文章主要為大家詳細介紹了python實現(xiàn)銀行實戰(zhàn)系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-02-02
  • python實現(xiàn)zabbix發(fā)送短信腳本

    python實現(xiàn)zabbix發(fā)送短信腳本

    這篇文章主要為大家詳細介紹了python實現(xiàn)zabbix發(fā)送短信腳本,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-09-09
  • python標準庫之time模塊的語法與簡單使用

    python標準庫之time模塊的語法與簡單使用

    在平常的代碼中,我們常常需要與時間打交道,那么在Python中,與時間處理有關(guān)的模塊就包括:time、datetime以及calendar,這篇文章主要給大家介紹了關(guān)于python標準庫之time模塊的語法與使用的相關(guān)資料,需要的朋友可以參考下
    2021-08-08
  • 在keras中model.fit_generator()和model.fit()的區(qū)別說明

    在keras中model.fit_generator()和model.fit()的區(qū)別說明

    這篇文章主要介紹了在keras中model.fit_generator()和model.fit()的區(qū)別說明,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-06-06
  • python實現(xiàn)水印生成器

    python實現(xiàn)水印生成器

    這篇文章主要為大家詳細介紹了python實現(xiàn)水印生成器,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-05-05
  • python連接sql?server數(shù)據(jù)庫的方法實戰(zhàn)

    python連接sql?server數(shù)據(jù)庫的方法實戰(zhàn)

    當我們用Python來編寫網(wǎng)站,必須要能夠通過python操作數(shù)據(jù)庫,下面這篇文章主要給大家介紹了關(guān)于python連接sql?server數(shù)據(jù)庫的相關(guān)資料,文中通過圖文介紹的非常詳細,需要的朋友可以參考下
    2022-08-08

最新評論