Help us understand the problem. What is going on with this article?

乱数配列

乱数の配列を生成する

numpy.randomモジュールに乱数に関する沢山の関数がある
勉強した3つを紹介する

numpy.random.rand()

0.0以上1.0未満の乱数を作成する

import numpy as np
a=np.random.rand()
print(a)
実行結果
0.13897360580695584

()の中を空にすると1つの乱数を作成する

a1=np.random.rand(2)
print(a1)
実行結果
array([0.57013166, 0.68758734])

()の中を2にしたことで(1×2)行列を作成できる

a2=np.random.rand(2,2)
print(a2)
実行結果
array([[0.66449092, 0.02173986],
       [0.4008564 , 0.08414578]])

(2,2)にすることで(2×2)行列を作成できる

numpy.random.randint()

任意の範囲の整数の乱数を作成する

a3=np.random.randint(1,10,(2,2))
#(low, high,size)
print(a3)
実行結果
array([[3, 2],
       [2, 4]])

a3は1以上10未満の2×2の配列の整数乱数を作成する

numpy.random.randn()

平均0,分散1の標準正規分布に従う乱数を作成する

a4=np.random.randn(3,3)
print(a4)
実行結果
array([[-0.36698874, -1.18990918, -0.29731787],
       [ 0.63560529,  1.42710657,  1.09983835],
       [-0.75945298,  1.34462223,  0.72328678]])
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした