Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
import numpy as np np.random.random(X) #where x is a positive integer
これにより、区間(0、1)のX番号の配列が得られます。ただし、数値を間隔(-1、1)に設定したいので、数値をnumpyでスケーリングする方法がわかりません。numpyだけを使用してこれを非常に簡単に行うにはどうすればよいですか?
あなたは単に使用することができますnp.random.uniform:
np.random.uniform
>>> import numpy as np >>> np.random.uniform(-1, 1, size=5) array([-0.32235009, -0.8347222 , -0.83968268, 0.78546736, 0.399747 ])
ランダム値に2を掛けてから、1を引きます。これにより、-1から1の範囲のランダム値が得られます。