溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

numpy.linspace 生成等差數(shù)組的方法

發(fā)布時(shí)間:2020-09-06 14:20:28 來源:腳本之家 閱讀:180 作者:WalkingAlien 欄目:開發(fā)技術(shù)

如下所示:

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

start:起始值 stop:結(jié)束值

num:生成的個(gè)數(shù)

endpoint True:包含 False:不包含 默認(rèn)True

restep:顯示相鄰兩數(shù)之差 默認(rèn)不顯示

dtype: 輸出類型 默認(rèn)不顯示

同時(shí),arange 是通過設(shè)置樣本之間的差值來生成數(shù)組的。

import numpy as np

x1 = np.linspace(2.0, 3.0, num=5)
print x1
x2 = np.linspace(2.0, 3.0, num=5, endpoint=False)
print x2
x3 = np.linspace(2.0, 3.0, num=5, retstep=True)
print x3

結(jié)果:

[ 2. 2.25 2.5 2.75 3. ] 
[ 2. 2.2 2.4 2.6 2.8] 
(array([ 2. , 2.25, 2.5 , 2.75, 3. ]), 0.25)

圖示:

import numpy as np
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")
plt.plot(x2, y + 0.5, 'o')
plt.ylim([-0.5, 1])
plt.show()

numpy.linspace 生成等差數(shù)組的方法

以上這篇numpy.linspace 生成等差數(shù)組的方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持億速云。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI