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

Numpy之random.randint產(chǎn)生隨機(jī)整數(shù)方式

 更新時(shí)間:2023年12月19日 09:54:20   作者:小虎AI實(shí)驗(yàn)室  
這篇文章主要介紹了Numpy之random.randint產(chǎn)生隨機(jī)整數(shù)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

前言

本文主要講述了如何使用Numpy的random.randint來(lái)產(chǎn)生隨機(jī)整數(shù),我們演示了如何生成不同上限或下限的指定大小的數(shù)組

方法

numpy.random.randint(low, high=None, size=None, dtype='l')

返回值

返回從低(包括)到高(不包括)的隨機(jī)整數(shù)。

從“半開”區(qū)間 [low, high) 中指定 dtype 的“離散均勻”分布返回隨機(jī)整數(shù)。

如果 high 為 None(默認(rèn)值),則結(jié)果來(lái)自 [0, low)。

參數(shù)

這個(gè)方法產(chǎn)生離散均勻分布的整數(shù),這些整數(shù)大于等于low,小于high。

  • low : int
  • 產(chǎn)生隨機(jī)數(shù)的最小值
  • high : int, optional
  • 給隨機(jī)數(shù)設(shè)置個(gè)上限,即產(chǎn)生的隨機(jī)數(shù)必須小于
  • highsize : int or tuple of ints, optional
  • 輸出的大小,可以是整數(shù),或者元組
  • dtype : dtype, optional
  • 期望結(jié)果的類型

結(jié)果

np.random.randint(2, size=10)

array([1, 0, 0, 0, 1, 1, 0, 0, 1, 0]) # random

生成 0 到 4 之間的 2 x 4 整數(shù)數(shù)組

np.random.randint(5, size=(2, 4))

array([[4, 0, 2, 1], # random
[3, 2, 2, 0]])

生成具有 3 個(gè)不同上限的 1 x 3 數(shù)組

np.random.randint(1, [3, 5, 10])

array([2, 2, 9]) # random

生成具有 3 個(gè)不同下限的 1 x 3 數(shù)組

np.random.randint([1, 5, 7], 10)

array([9, 8, 7]) # random

使用 dtype 為 uint8 的廣播生成 2 x 4 數(shù)組

np.random.randint([1, 3, 5, 7], [[10], [20]], dtype=np.uint8)

array([[ 8, 6, 9, 7], # random
[ 1, 16, 9, 12]], dtype=uint8)

實(shí)驗(yàn)

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論