Movatterモバイル変換


[0]ホーム

URL:


SciPy

numpy.random.random_sample

numpy.random.random_sample(size=None)

Return random floats in the half-open interval [0.0, 1.0).

Results are from the “continuous uniform” distribution over thestated interval. To sampleUnif[a, b), b > a multiplythe output ofrandom_sample by(b-a) and adda:

(b-a)*random_sample()+a
Parameters:
size:int or tuple of ints, optional

Output shape. If the given shape is, e.g.,(m,n,k), thenm*n*k samples are drawn. Default is None, in which case asingle value is returned.

Returns:
out:float or ndarray of floats

Array of random floats of shapesize (unlesssize=None, in whichcase a single float is returned).

Examples

>>>np.random.random_sample()0.47108547995356098>>>type(np.random.random_sample())<type 'float'>>>>np.random.random_sample((5,))array([ 0.30220482,  0.86820401,  0.1654503 ,  0.11659149,  0.54323428])

Three-by-two array of random numbers from [-5, 0):

>>>5*np.random.random_sample((3,2))-5array([[-3.99149989, -0.52338984],       [-2.99091858, -0.79479508],       [-1.23204345, -1.75224494]])

Previous topic

numpy.random.random_integers

Next topic

numpy.random.random

Quick search

  • © Copyright 2008-2018, The SciPy community.
  • Last updated on Jul 24, 2018.
  • Created usingSphinx 1.6.6.

[8]ページ先頭

©2009-2025 Movatter.jp