0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Python】NumPyのrandomモジュール

Posted at

random.randは「0以上10未満」ではなく、「0以上1未満」の小数をランダムに返します。

randomモジュールの関数をまとめると以下になります。

【概要】

rand → 0以上1未満の小数
random → 0以上1未満の小数、引数がタプル
uniform → 指定範囲の小数
randint → 指定範囲の整数
randn → 平均0・分散1の標準正規分布
normal → 指定の平均・標準偏差の正規分布

【詳細】

■ rand (0以上1未満の小数)
rand(a)
0以上1未満の小数をa個返す。

rand(x, y)
0以上1未満の小数をx行y列で返す。

■ random (0以上1未満の小数、引数がタプル)
random((x, y))
0以上1未満の小数をx行y列で返す。

■ uniform (指定範囲の小数)
uniform(a, b, size=(x, y))
a以上b未満の範囲の小数をx行y列で返す。

■ randint (指定範囲の整数)
randint(a)
0〜a-1の整数を1つ返す。

randint(a, b)
a〜b-1の範囲で整数を1つ返す。

randint(a, b size=(x, y))
a〜b-1の範囲の整数をx行y列で返す。

randint(a, b, c)
a〜b-1の範囲の整数をc個返す。

■ randn (標準正規分布)
平均0、分散1の標準正規分布に従って小数を返す。
引数はrandと同じ。

■ normal (指定の正規分布)
normal(平均, 標準偏差, size=(x, y))
指定した平均と標準偏差の正規分布に従った小数をx行y列で返す。

すべて「np.random.〜」の記述で使います。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?