[問題] numpy.random.randint的用法解釋

看板Python作者 (早知道就去歐洲定居)時間6年前 (2019/08/02 12:36), 編輯推噓1(102)
留言3則, 2人參與, 6年前最新討論串1/1
看document https:// docs.scipy.org/doc/numpy-1.15.1/reference/generated/numpy.random.randint.html low : int Lowest (signed) integer to be drawn from the distribution (unless high=None, in which case this parameter is one above the highest such integer). 可是為什麼下面範例 np.random.randint(2, size=10) 抽出的值是0跟1? (unless high=None, in which case this parameter is one above the highest such integer). this parameter "2" is one above the highest such integer 的意思是說 抽出的最大值是2-1 這樣理解對嗎? such integer說的是抽出的integer? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 80.213.1.89 (挪威) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1564720591.A.B8D.html

08/02 15:05, 6年前 , 1F
除非你有給high 否則low就是high
08/02 15:05, 1F

08/02 15:28, 6年前 , 2F
high是None的情況下, 你給的low會當成high, 而low預設為0
08/02 15:28, 2F

08/02 15:28, 6年前 , 3F
range也是類似的做法
08/02 15:28, 3F
文章代碼(AID): #1TGxtFkD (Python)
文章代碼(AID): #1TGxtFkD (Python)