欧美成人午夜免费全部完,亚洲午夜福利精品久久,а√最新版在线天堂,另类亚洲综合区图片小说区,亚洲欧美日韩精品色xxx

扣丁學堂Python培訓簡述random.randint()與np.random.randint()的區(qū)別

2019-04-19 15:39:03 3065瀏覽

本篇文章扣丁學堂Python培訓小編給讀者們分享一下random.randint()與np.random.randint()的區(qū)別,對Python開發(fā)技術感興趣的小伙伴就隨小編一起來了解一下吧。

扣丁學堂Python培訓簡述random.randint()與np.random.randint()的區(qū)別


先來看看random.randint()方法:

importrandom
forninrange(5):
foriinrange(10):
print(random.randint(1,5),end='')
print()
#運行結果
1553313152
4444443152
3231155143
3442553444
3545454524
Processfinishedwithexitcode0
再來看看numpy.random.randint()方法:

importnumpyasnp
forninrange(5):
foriinrange(10):
print(np.random.randint(1,5),end='')
print()

#運行結果
2411112224
3432343224
2212113334
4142413432
2332344344
Processfinishedwithexitcode0
看出有什么不同了嗎?**random.randint()方法里面的取值區(qū)間是前閉后閉區(qū)間,而np.random.randint()方法的取值區(qū)間是前閉后開區(qū)間**,是它們的最大區(qū)別。使用的時候一定要注意。
再來詳細看看這兩個方法吧。

random.randint(a,b[,c])
#用于生成一個指定范圍內的整數(shù)。其中參數(shù)a是下限,參數(shù)b是上限,生成的隨機數(shù)n:a<=n<=b。c是步幅。
例如:
1)print(random.randint(12,20))#生成的隨機數(shù)n:12<=n<=20
2)print(random.randint(20,20))#結果永遠是20
3)print(random.randint(20,10))#該語句是錯誤的。因為下限必須小于上限。
randint.randrange()函數(shù)在隨機是不包括上限數(shù)的。

numpy.random.randint(low,high=None,size=None,dtype='l')
#這個方法產生離散均勻分布的整數(shù),這些整數(shù)大于等于low,小于high。
low:int#產生隨機數(shù)的最小值
high:int,optional#給隨機數(shù)設置個上限,即產生的隨機數(shù)必須小于high
size:intortupleofints,optional#整數(shù),生成隨機元素的個數(shù)或者元組,數(shù)組的行和列
dtype:dtype,optional#期望結果的類型
![numpy.png](https://upload-images.jianshu.io/upload_images/14750449-4dafa78330d39e93.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)



以上就是扣丁學堂Python在線學習小編給大家分享的random.randint()與np.random.randint()的區(qū)別,希望對小伙伴們有所幫助,想要了解更多內容的小伙伴可以登錄扣丁學堂官網咨詢。


想要學好Python開發(fā)小編給大家推薦口碑良好的扣丁學堂,扣丁學堂有專業(yè)老師制定的Python學習路線圖輔助學員學習,此外還有與時俱進的Python課程體系和Python視頻教程供大家學習,想要學好Python開發(fā)技術的小伙伴快快行動吧??鄱W堂Python技術交流群:279521237。


扣丁學堂微信公眾號                          Python全棧開發(fā)爬蟲人工智能機器學習數(shù)據分析免費公開課直播間


      【關注微信公眾號獲取更多學習資料】         【掃碼進入Python全棧開發(fā)免費公開課】



查看更多關于"Python開發(fā)資訊"的相關文章>


標簽: Python培訓 Python視頻教程 Python在線視頻 Python學習視頻 Python培訓班

熱門專區(qū)

暫無熱門資訊

課程推薦

微信
微博
15311698296

全國免費咨詢熱線

郵箱:codingke@1000phone.com

官方群:148715490

北京千鋒互聯(lián)科技有限公司版權所有   北京市海淀區(qū)寶盛北里西區(qū)28號中關村智誠科創(chuàng)大廈4層
京ICP備2021002079號-2   Copyright ? 2017 - 2022
返回頂部 返回頂部