numpy.random.randint()> numpyでランダムサンプリングを行う関数の一つです。指定された形状の配列を返し、その配列を低 (これを含む) から高 (これを含まない) まで、つまり間隔内でランダムな整数で埋めます。 [low, high).>
構文: numpy.random.randint(low、high=なし、size=なし、dtype=’l’)
パラメーター :
低い : [int] 分布から抽出される最小の (符号付き) 整数。ただし、high=None の場合、サンプル内の最大の整数として機能します。
高い : [int、オプション] 分布から抽出される最大の (符号付き) 整数。
サイズ : [int または int のタプル、オプション] 出力形状。指定された形状が (m, n, k) の場合、m * n * k 個のサンプルが描画されます。デフォルトは None で、この場合は単一の値が返されます。
dtype : [オプション] 必要な出力データ型。
戻る : 間隔内のランダムな整数の配列
[low, high)>サイズが指定されていない場合は、単一のランダムな int です。
コード #1 :
# Python program explaining> # numpy.random.randint() function> > # importing numpy> import> numpy as geek> > # output array> out_arr>=> geek.random.randint(low>=> 0>, high>=> 3>, size>=> 5>)> print> (>'Output 1D Array filled with random integers : '>, out_arr)> |
>
>出力:
Output 1D Array filled with random integers : [1 1 0 1 1]>
コード #2 :
# Python program explaining> # numpy.random.randint() function> > # importing numpy> import> numpy as geek> > > # output array> out_arr>=> geek.random.randint(low>=> 4>, size>=>(>2>,>3>))> print> (>'Output 2D Array filled with random integers : '>, out_arr)> |
>
二分木と二分探索木
>出力:
Output 2D Array filled with random integers : [[1 1 0] [1 0 3]]>
コード #3 :
# Python program explaining> # numpy.random.randint() function> > # importing numpy> import> numpy as geek> > # output array> out_arr>=> geek.random.randint(>2>,>10>, (>2>,>3>,>4>))> print> (>'Output 3D Array filled with random integers : '>, out_arr)> |
>
>出力:
Output 3D Array filled with random integers : [[[4 8 5 7] [6 5 6 7] [4 3 4 3]] [[2 9 2 2] [3 2 2 3] [6 8 3 2]]]>