find module

random_sample(size=None)

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

Results are from the “continuous uniform” distribution over the stated interval. To sample \(Unif[a, b), b > a\) multiply the output of random_sample by (b-a) and add a:

(b - a) * random_sample() + a

Note

New code should use the random method of a default_rng() instance instead; please see the random-quick-start.

Parameters

size (int or tuple of ints, optional) – Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. Default is None, in which case a single value is returned.

Returns

out – Array of random floats of shape size (unless size=None, in which case a single float is returned).

Return type

float or ndarray of floats

See also

Generator.random()

which should be used for new code.

Examples

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

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

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

Find a appropriate value to test the property of the return_type

Parameters
  • prop_dict (dict) – Dictionary containing the property informations

  • return_type (str) – type of the value for the test (can be different of the property one)

Returns

value – A “return_type” value for the test

Return type

?

find_test_ndarray(prop_dict)[source]

Find a correct value to test ndarray

Parameters

prop_dict (dict) – dictionary containing the information of the property to test

Returns

value – A value to test the property

Return type

numpy.ndarray

find_num_value(prop_dict, is_int_return)[source]

Find a value to test Double or Integer matching min/max

Parameters
  • prop_dict (dict) – dictionary containing the information on the property to test

  • is_int_return (bool) – To convert the value to int (if needed)

Returns

value – value for the test

Return type

int/float

is_type_list(type_name)[source]

Check if the type_name is a list of pyleecan objects “[class_name]”

Parameters

type_name (str) – name of the type to test

Returns

is_list – True if the type is a list of pyleecan objects

Return type

bool

is_type_dict(type_name)[source]

Check if the type_name is a dict of pyleecan objects “{class_name}”

Parameters

type_name (str) – name of the type to test

Returns

is_list – True if the type is a dict of pyleecan objects

Return type

bool

exception MissingTypeError[source]

Bases: Exception