Random#
- class ivy.data_classes.container.random._ContainerWithRandom(dict_in=None, queues=None, queue_load_sizes=None, container_combine_method='list_join', queue_timeout=None, print_limit=10, key_length_limit=None, print_indent=4, print_line_spacing=0, ivyh=None, default_key_color='green', keyword_color_dict=None, rebuild_child_containers=False, types_to_iteratively_nest=None, alphabetical_keys=True, dynamic_backend=None, build_callable=False, **kwargs)[source]#
Bases:
ContainerBase
- _abc_impl = <_abc._abc_data object>#
- static _static_multinomial(population_size, num_samples, /, *, batch_size=1, probs=None, replace=True, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, device=None, seed=None, out=None)[source]#
ivy.Container static method variant of ivy.multinomial. This method simply wraps the function, and so the docstring for ivy.multinomial also applies to this method with minimal changes.
- Parameters:
population_size (
Union
[int
,Container
]) – The size of the population from which to draw samples.num_samples (
Union
[int
,Container
]) – Number of independent samples to draw from the population.batch_size (
Union
[int
,Container
], default:1
) – Number of tensors to generate. Default is 1.probs (
Optional
[Union
[Array
,NativeArray
,Container
]], default:None
) – The unnormalized probabilities for all elements in population, default is uniform [batch_shape, population_size]replace (
Union
[bool
,Container
], default:True
) – Whether to replace samples once they’ve been drawn. Default isTrue
.key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
],Container
]], default:None
) – The key-chains to apply or not apply the method to. Default isNone
.to_apply (
Union
[bool
,Container
], default:True
) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue
.prune_unapplied (
Union
[bool
,Container
], default:False
) – Whether to prune key_chains for which the function was not applied. Default isFalse
.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.device (
Optional
[Union
[Device
,NativeDevice
,Container
]], default:None
) – device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc. (Default value = None)seed (
Optional
[Union
[int
,Container
]], default:None
) – A python integer. Used to create a random seed distributionout (
Optional
[Container
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
Container
- Returns:
ret – Drawn samples from the parameterized normal distribution.
- static _static_randint(low, high, /, *, shape=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, device=None, dtype=None, seed=None, out=None)[source]#
ivy.Container static method variant of ivy.randint. This method simply wraps the function, and so the docstring for ivy.randint also applies to this method with minimal changes.
- Parameters:
low (
Union
[int
,Container
,Array
,NativeArray
]) – Lowest integer that can be drawn from the distribution.high (
Union
[int
,Container
,Array
,NativeArray
]) – One above the highest integer that can be drawn from the distribution.shape (
Optional
[Union
[Shape
,NativeShape
,Container
]], default:None
) – If the given shape is, e.g(m, n, k)
, thenm * n * k
samples are drawn. Can only be specified whenlow
andhigh
are numeric values, else exception will be raised. Default isNone
, where a single value is returned.key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
],Container
]], default:None
) – The key-chains to apply or not apply the method to. Default isNone
.to_apply (
Union
[bool
,Container
], default:True
) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue
.prune_unapplied (
Union
[bool
,Container
], default:False
) – Whether to prune key_chains for which the function was not applied. Default isFalse
.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.device (
Optional
[Union
[Device
,NativeDevice
,Container
]], default:None
) – device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc. (Default value = None).dtype (
Optional
[Union
[Dtype
,NativeDtype
,Container
]], default:None
) – output array data type. Ifdtype
isNone
, the output array data type will be the default integer data type. DefaultNone
seed (
Optional
[Union
[int
,Container
]], default:None
) – A python integer. Used to create a random seed distributionout (
Optional
[Container
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
Container
- Returns:
ret – Returns an array with the given shape filled with integers from the uniform distribution in the “half-open” interval [low, high)
Examples
With
ivy.Container
inputs:>>> x = ivy.Container(a=ivy.array([[9,7],[6,2]]), ... b=ivy.array([[0,2],[10,6]])) >>> y = ivy.Container(a=ivy.array([[10,32],[18,19]]), ... b=ivy.array([[44,5],[23,54]])) >>> ivy.Container.static_randint(x, y, device='cpu', dtype='int32') { a: ivy.array([[9, 27], [16, 17]]), b: ivy.array([[13, 3], [16, 19]]) }
With a mix of
ivy.Array
andivy.Container
inputs:>>> x = ivy.array([-1,-9,3]) >>> y = ivy.Container(a=ivy.array([4,7,9]),b=ivy.array([14,17,34])) >>> ivy.Container.static_randint(x, y) { a: ivy.array([1, 6, 5]), b: ivy.array([0, 10, 17]) }
- static _static_random_normal(*, mean=0.0, std=1.0, shape=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, device=None, dtype=None, seed=None, out=None)[source]#
ivy.Container static method variant of ivy.random_normal. This method simply wraps the function, and so the docstring for ivy.random_normal also applies to this method with minimal changes.
- Parameters:
mean (
Union
[float
,Container
,Array
,NativeArray
], default:0.0
) – The mean of the normal distribution to sample from. Default is0.0
.std (
Union
[float
,Container
,Array
,NativeArray
], default:1.0
) – The standard deviation of the normal distribution to sample from. Must be non-negative. Default is1.0
.shape (
Optional
[Union
[Shape
,NativeShape
,Container
]], default:None
) – If the given shape is, e.g(m, n, k)
, thenm * n * k
samples are drawn. Can only be specified whenmean
andstd
are numeric values, else exception will be raised. Default isNone
, where a single value is returned.key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
],Container
]], default:None
) – The key-chains to apply or not apply the method to. Default isNone
.to_apply (
Union
[bool
,Container
], default:True
) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue
.prune_unapplied (
Union
[bool
,Container
], default:False
) – Whether to prune key_chains for which the function was not applied. Default isFalse
.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.device (
Optional
[Union
[Device
,NativeDevice
,Container
]], default:None
) – device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc. (Default value = None).dtype (
Optional
[Union
[Dtype
,NativeDtype
,Container
]], default:None
) – output array data type. Ifdtype
isNone
, the output array data type will be the default floating-point data type. DefaultNone
seed (
Optional
[Union
[int
,Container
]], default:None
) – A python integer. Used to create a random seed distributionout (
Optional
[Container
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
Container
- Returns:
ret – Drawn samples from the parameterized normal distribution.
Examples
With
ivy.Container
inputs:>>> x = ivy.Container(a=ivy.array([[9.8,7.6],[6.5,2.3]]), ... b=ivy.array([[0.9,2.4],[7.6,5.4]])) >>> y = ivy.Container(a=ivy.array([[10.9,32.4],[18.7,19.6]]), ... b=ivy.array([[4.3,5.6],[23.4,54.3]])) >>> ivy.Container.static_random_normal(mean=x, std=y, device='cpu', ... dtype='float64') { a: ivy.array([[-4.11, 0.651], [19.3, -30.4]]), b: ivy.array([[1.15, 3.39], [-9.35, -13.9]]) }
With a mix of
ivy.Array
andivy.Container
inputs:>>> x = ivy.array([-1.0,-9.0,-3.4]) >>> y = ivy.Container(a=ivy.array([0.6, 0.2, 0.3]),b=ivy.array([0.8, 0.2, 0.2])) >>> ivy.Container.static_random_normal(mean=x, std=y) { a: ivy.array([-0.651, -9.25, -3.54]), b: ivy.array([0.464, -8.51, -3.75]) }
- static _static_random_uniform(*, low=0.0, high=1.0, shape=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, device=None, dtype=None, seed=None, out=None)[source]#
ivy.Container static method variant of ivy.random_uniform. This method simply wraps the function, and so the docstring for ivy.random_uniform also applies to this method with minimal changes.
- Parameters:
low (
Union
[float
,Container
,Array
,NativeArray
], default:0.0
) – Lower boundary of the output interval. All values generated will be greater than or equal tolow
. If array, must have same shape ashigh
.high (
Union
[float
,Container
,Array
,NativeArray
], default:1.0
) – Upper boundary of the output interval. All the values generated will be less thanhigh
. If array, must have same shape aslow
.shape (
Optional
[Union
[Shape
,NativeShape
,Container
]], default:None
) – If the given shape is, e.g(m, n, k)
, thenm * n * k
samples are drawn. Can only be specified whenlow
andhigh
are numeric values, else exception will be raised. Default isNone
, where a single value is returned.key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
],Container
]], default:None
) – The key-chains to apply or not apply the method to. Default isNone
.to_apply (
Union
[bool
,Container
], default:True
) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue
.prune_unapplied (
Union
[bool
,Container
], default:False
) – Whether to prune key_chains for which the function was not applied. Default isFalse
.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.device (
Optional
[Union
[Device
,NativeDevice
,Container
]], default:None
) – device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc. (Default value = None).dtype (
Optional
[Union
[Dtype
,NativeDtype
,Container
]], default:None
) – output array data type. Ifdtype
isNone
, the output array data type will be the default floating-point data type. DefaultNone
seed (
Optional
[Union
[int
,Container
]], default:None
) – A python integer. Used to create a random seed distributionout (
Optional
[Container
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
Container
- Returns:
ret – Drawn samples from the parameterized uniform distribution.
Examples
With
ivy.Container
inputs:>>> x = ivy.Container(a=ivy.array([[9.8,7.6],[6.5,2.3]]), ... b=ivy.array([[0.9,2.4],[7.6,5.4]])) >>> y = ivy.Container(a=ivy.array([[10.9,32.4],[18.7,19.6]]), ... b=ivy.array([[4.3,5.6],[23.4,54.3]])) >>> ivy.Container.static_random_uniform(low=x, high=y, device='cpu', ... dtype='float64') { a: ivy.array([[10.8, 23.7], [17., 16.6]]), b: ivy.array([[2.35, 3.69], [17.4, 48.]]) }
With a mix of
ivy.Array
andivy.Container
inputs:>>> x = ivy.array([-1.0,-9.0,-3.4]) >>> y = ivy.Container(a=ivy.array([0.6, 0.2, 0.3]),b=ivy.array([0.8, 0.2, 0.2])) >>> ivy.Container.static_random_uniform(low=x, high=y) { a: ivy.array([0.481, -8.03, -2.74]), b: ivy.array([0.0999, -7.38, -1.29]) }
- static _static_shuffle(x, axis=0, /, *, seed=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#
ivy.Container static method variant of ivy.shuffle. This method simply wraps the function, and so the docstring for ivy.shuffle also applies to this method with minimal changes.
- Parameters:
x (
Union
[int
,Container
,Array
,NativeArray
]) – Input array or container. Should have a numeric data type.axis (
Optional
[Union
[int
,Container
]], default:0
) – The axis which input array or container is shuffled along. Default is 0.seed (
Optional
[Union
[int
,Container
]], default:None
) – A python integer. Used to create a random seed distributionkey_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
],Container
]], default:None
) – The key-chains to apply or not apply the method to. Default isNone
.to_apply (
Union
[bool
,Container
], default:True
) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue
.prune_unapplied (
Union
[bool
,Container
], default:False
) – Whether to prune key_chains for which the function was not applied. Default isFalse
.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.out (
Optional
[Container
], default:None
) – optional output container, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
Container
- Returns:
ret – A container object, shuffled along the first dimension.
Examples
>>> x = ivy.Container(a=ivy.array([7, 6, 0]), ... b=ivy.array([8, 9, 4])) >>> ivy.Container.static_shuffle(x) { a: ivy.array([7, 0, 6]), b: ivy.array([8, 4, 9]) }
- multinomial(population_size, num_samples, /, *, batch_size=1, replace=True, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, device=None, seed=None, out=None)[source]#
ivy.Container instance method variant of ivy.multinomial. This method simply wraps the function, and so the docstring for ivy.multinomial also applies to this method with minimal changes.
- Parameters:
self (
Container
) – The unnormalized probabilities for all elements in population, default is uniform [batch_shape, population_size]population_size (
Union
[int
,Container
]) – The size of the population from which to draw samples.num_samples (
Union
[int
,Container
]) – Number of independent samples to draw from the population.batch_size (
Union
[int
,Container
], default:1
) – Number of tensors to generate. Default is 1.replace (
Union
[bool
,Container
], default:True
) – Whether to replace samples once they’ve been drawn. Default isTrue
.key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
],Container
]], default:None
) – The key-chains to apply or not apply the method to. Default isNone
.to_apply (
Union
[bool
,Container
], default:True
) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue
.prune_unapplied (
Union
[bool
,Container
], default:False
) – Whether to prune key_chains for which the function was not applied. Default isFalse
.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.device (
Optional
[Union
[Device
,NativeDevice
,Container
]], default:None
) – device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc. (Default value = None)seed (
Optional
[Union
[int
,Container
]], default:None
) – A python integer. Used to create a random seed distributionout (
Optional
[Container
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
Container
- Returns:
ret – Drawn samples from the parameterized normal distribution.
- randint(high, /, *, shape=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, device=None, dtype=None, seed=None, out=None)[source]#
ivy.Container instance method variant of ivy.randint. This method simply wraps the function, and so the docstring for ivy.randint also applies to this method with minimal changes.
- Parameters:
self (
Container
) – Lowest integer that can be drawn from the distribution.high (
Union
[int
,Container
,Array
,NativeArray
]) – One above the highest integer that can be drawn from the distribution.shape (
Optional
[Union
[Shape
,NativeShape
,Container
]], default:None
) – If the given shape is, e.g(m, n, k)
, thenm * n * k
samples are drawn. Can only be specified whenlow
andhigh
are numeric values, else exception will be raised. Default isNone
, where a single value is returned.key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
],Container
]], default:None
) – The key-chains to apply or not apply the method to. Default isNone
.to_apply (
Union
[bool
,Container
], default:True
) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue
.prune_unapplied (
Union
[bool
,Container
], default:False
) – Whether to prune key_chains for which the function was not applied. Default isFalse
.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.device (
Optional
[Union
[Device
,NativeDevice
,Container
]], default:None
) – device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc. (Default value = None).dtype (
Optional
[Union
[Dtype
,NativeDtype
,Container
]], default:None
) – output array data type. Ifdtype
isNone
, the output array data type will be the default integer data type. DefaultNone
seed (
Optional
[Union
[int
,Container
]], default:None
) – A python integer. Used to create a random seed distributionout (
Optional
[Container
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
Container
- Returns:
ret – Returns an array with the given shape filled with integers from the uniform distribution in the “half-open” interval [low, high)
Examples
>>> x = ivy.Container(a=ivy.array([7,6,0]), ... b=ivy.array([8,9,4])) >>> x.randint(30) { a: ivy.array([23, 15, 20]), b: ivy.array([28, 22, 18]) }
>>> x.randint(10, device='cpu') { a: ivy.array([9, 7, 7]), b: ivy.array([8, 9, 9]) }
>>> x.randint(102, dtype='int8') { a: ivy.array([9, 8, 2]), b: ivy.array([62, 62, 60]) }
>>> x.randint(54, device='cpu', dtype='int64') { a: ivy.array([30, 29, 26]), b: ivy.array([24, 24, 21]) }
>>> z = ivy.Container(a=ivy.zeros((3,)), b=ivy.ones((3,))) >>> x.randint(21, device='cpu', dtype='int8', out=z) { a: ivy.array([7, 6, 0]), b: ivy.array([8, 9, 4]) }
>>> y = ivy.Container(a=54, b=17) >>> x.randint(y) { a: ivy.array([7, 6, 0]), b: ivy.array([8, 9, 4]) }
>>> x.randint(y, device='cpu') { a: ivy.array([7, 6, 0]), b: ivy.array([8, 9, 4]) }
>>> x.randint(y, dtype='int64') { a: ivy.array([7, 6, 0]), b: ivy.array([8, 9, 4]) }
>>> x.randint(y, device='cpu', dtype='int32') { a: ivy.array([7, 6, 0]), b: ivy.array([8, 9, 4]) }
>>> z = ivy.Container(a=ivy.zeros((3,)), b=ivy.ones((3,))) >>> x.randint(y, device='cpu', dtype='int16', out=z) { a: ivy.array([7, 6, 0]), b: ivy.array([8, 9, 4]) }
>>> x = ivy.Container(a=ivy.array([[9,7],[6,2]]), ... b=ivy.array([[0,2],[10,6]])) >>> y = ivy.Container(a=ivy.array([[10,32],[18,19]]), ... b=ivy.array([[44,5],[23,54]])) >>> x.randint(y) { a: ivy.array([[9, 7], [6, 2]]), b: ivy.array([[0, 2], [10, 6]]) }
>>> x.randint(y, device='cpu') { a: ivy.array([[9, 7], [6, 2]]), b: ivy.array([[0, 2], [10, 6]]) }
>>> x.randint(y, dtype='int64') { a: ivy.array([[9, 7], [6, 2]]), b: ivy.array([[0, 2], [10, 6]]) }
>>> x.randint(y, device='cpu', dtype='int32') { a: ivy.array([[9, 7], [6, 2]]), b: ivy.array([[0, 2], [10, 6]]) }
>>> z = ivy.Container(a=ivy.zeros((2,2)), b=ivy.ones((2,2))) >>> x.randint(y, device='cpu', dtype='int16', out=z) { a: ivy.array([[9, 7], [6, 2]]), b: ivy.array([[0, 2], [10, 6]]) }
- random_normal(*, std=1.0, shape=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, device=None, dtype=None, seed=None, out=None)[source]#
ivy.Container instance method variant of ivy.random_normal. This method simply wraps the function, and so the docstring for ivy.random_normal also applies to this method with minimal changes.
- Parameters:
self (
Container
) – The mean of the normal distribution to sample from. Default is0.0
.std (
Union
[float
,Container
,Array
,NativeArray
], default:1.0
) – The standard deviation of the normal distribution to sample from. Must be non-negative. Default is1.0
.shape (
Optional
[Union
[Shape
,NativeShape
,Container
]], default:None
) – If the given shape is, e.g(m, n, k)
, thenm * n * k
samples are drawn. Can only be specified whenmean
andstd
are numeric values, else exception will be raised. Default isNone
, where a single value is returned.key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
],Container
]], default:None
) – The key-chains to apply or not apply the method to. Default isNone
.to_apply (
Union
[bool
,Container
], default:True
) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue
.prune_unapplied (
Union
[bool
,Container
], default:False
) – Whether to prune key_chains for which the function was not applied. Default isFalse
.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.device (
Optional
[Union
[Device
,NativeDevice
,Container
]], default:None
) – device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc. (Default value = None).dtype (
Optional
[Union
[Dtype
,NativeDtype
,Container
]], default:None
) – output array data type. Ifdtype
isNone
, the output array data type will be the default floating-point data type. DefaultNone
seed (
Optional
[Union
[int
,Container
]], default:None
) – A python integer. Used to create a random seed distributionout (
Optional
[Container
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
Container
- Returns:
ret – Drawn samples from the parameterized normal distribution.
Examples
>>> x = ivy.Container(a=ivy.array([7.5,6.7,0.9]), ... b=ivy.array([8.7,9.8,4.5])) >>> x.random_normal(std=17.4) { a: ivy.array([11.9, -22.9, -24.8]), b: ivy.array([44.3, -21.6, 2.03]) }
>>> x.random_normal(std=10.2, device='cpu') { a: ivy.array([7.82, 6.21, -0.431]), b: ivy.array([13.8, 9.9, 7.64]) }
>>> x.random_normal(std=14.2, dtype='float16') { a: ivy.array([-18.3, -3.42, 9.55]), b: ivy.array([-1.31, 7.68, -6.93]) }
>>> x.random_normal(std=10.8, device='cpu', dtype='float64') { a: ivy.array([13.4, -3.14, 10.7]), b: ivy.array([11.7, 4.85, 5.83]) }
>>> z = ivy.Container(a=ivy.zeros((3,)), b=ivy.ones((3,))) >>> x.random_normal(std=11.2, device='cpu', dtype='float64', out=z) { a: ivy.array([-6.84, 0.274, 14.2]), b: ivy.array([29.1, 7.19, 3.]) }
>>> y = ivy.Container(a=10.4, b=17.4) >>> x.random_normal(std=y) { a: ivy.array([-9.5, 8.54, -9.13]), b: ivy.array([-24.5, 18.9, 11.]) }
>>> x.random_normal(std=y, device='cpu') { a: ivy.array([8.47, 8.23, 8.69]), b: ivy.array([10.7, 16.2, 16.1]) }
>>> x.random_normal(std=y, dtype='float16') { a: ivy.array([8.22, -15.9, 10.4]), b: ivy.array([19.9, 11.5, -2.15]) }
>>> x.random_normal(std=y, device='cpu', dtype='float64') { a: ivy.array([19.6, -4.08, 6.09]), b: ivy.array([-23.9, 6.86, 17.6]) }
>>> z = ivy.Container(a=ivy.zeros((3,)), b=ivy.ones((3,))) >>> x.random_normal(std=y, device='cpu', dtype='float64', out=z) { a: ivy.array([14.7, 8.99, 8.46]), b: ivy.array([22.9, -5.97, -1.28]) }
>>> x = ivy.Container(a=ivy.array([[9.8,7.6],[6.5,2.3]]), ... b=ivy.array([[0.9,2.4],[7.6,5.4]])) >>> y = ivy.Container(a=ivy.array([[10.9,32.4],[18.7,19.6]]), ... b=ivy.array([[4.3,5.6],[23.4,54.3]])) >>> x.random_normal(std=y) { a: ivy.array([[10.6, 7.89], [9.39, 19.4]]), b: ivy.array([[3.76, 4.68], [17.7, 24.]]) }
>>> x.random_normal(std=y, device='cpu') { a: ivy.array([[30.9, 24.6], [29.9, -25.3]]), b: ivy.array([[8.02, 1.92], [-5.34, -54.1]]) }
>>> x.random_normal(std=y, dtype='float16') { a: ivy.array([[7.82, -35.], [11.7, 0.696]]), b: ivy.array([[-4.07, -2.91], [19.2, 46.8]]) }
>>> x.random_normal(std=y, device='cpu', dtype='float64') { a: ivy.array([[25.4, 28.3], [19.6, -9.83]]), b: ivy.array([[2.95, 2.48], [-30.8, -40.1]]) }
>>> z = ivy.Container(a=ivy.zeros((2,2)), b=ivy.ones((2,2))) >>> x.random_normal(std=y, device='cpu', dtype='float64', out=z) { a: ivy.array([[2.8, -45.6], [-10.4, 0.65]]), b: ivy.array([[3.8, 1.43], [23., 29.4]]) }
- random_uniform(*, high=1.0, shape=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, device=None, dtype=None, seed=None, out=None)[source]#
ivy.Container instance method variant of ivy.random_uniform. This method simply wraps the function, and so the docstring for ivy.random_uniform also applies to this method with minimal changes.
- Parameters:
self (
Container
) – Lower boundary of the output interval. All values generated will be greater than or equal tolow
. If array, must have same shape ashigh
.high (
Union
[float
,Container
,Array
,NativeArray
], default:1.0
) – Upper boundary of the output interval. All the values generated will be less thanhigh
. If array, must have same shape aslow
.shape (
Optional
[Union
[Shape
,NativeShape
,Container
]], default:None
) – If the given shape is, e.g(m, n, k)
, thenm * n * k
samples are drawn. Can only be specified whenlow
andhigh
are numeric values, else exception will be raised. Default isNone
, where a single value is returned.key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
],Container
]], default:None
) – The key-chains to apply or not apply the method to. Default isNone
.to_apply (
Union
[bool
,Container
], default:True
) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue
.prune_unapplied (
Union
[bool
,Container
], default:False
) – Whether to prune key_chains for which the function was not applied. Default isFalse
.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.device (
Optional
[Union
[Device
,NativeDevice
,Container
]], default:None
) – device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc. (Default value = None).dtype (
Optional
[Union
[Dtype
,NativeDtype
,Container
]], default:None
) – output array data type. Ifdtype
isNone
, the output array data type will be the default floating-point data type. DefaultNone
seed (
Optional
[Union
[int
,Container
]], default:None
) – A python integer. Used to create a random seed distributionout (
Optional
[Container
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
Container
- Returns:
ret – Drawn samples from the parameterized uniform distribution.
Examples
>>> x = ivy.Container(a=ivy.array([7.5,6.7,0.9]), b=ivy.array([8.7,9.8,4.5])) >>> x.random_uniform(high=17.4) { a: ivy.array([11.2, 10.5, 13.1]), b: ivy.array([11.2, 11.9, 6.01]) }
>>> x.random_uniform(high=10.2, device='cpu') { a: ivy.array([8.55, 10.1, 4.08]), b: ivy.array([9.45, 9.9, 8.6]) }
>>> x.random_uniform(high=14.2, dtype='float16') { a: ivy.array([12.4, 11.7, 7.25]), b: ivy.array([11.8, 11.8, 4.96]) }
>>> x.random_uniform(high=10.8, device='cpu', dtype='float64') { a: ivy.array([8.86, 9.24, 6.43]), b: ivy.array([8.95, 10.1, 8.51]) }
>>> z = ivy.Container(a=ivy.zeros((3,)), b=ivy.ones((3,))) >>> x.random_uniform(high=11.2, device='cpu', dtype='float64', out=z) { a: ivy.array([9.6, 8.24, 3.67]), b: ivy.array([9.29, 11.2, 9.84]) }
>>> y = ivy.Container(a=10.4, b=17.4) >>> x.random_uniform(high=y) { a: ivy.array([8.24, 9.22, 1.52]), b: ivy.array([16.5, 13.4, 17.3]) }
>>> x.random_uniform(high=y, device='cpu') { a: ivy.array([8.55, 10.1, 4.08]), b: ivy.array([9.45, 9.9, 8.6]) }
>>> x.random_uniform(high=y, dtype='float16') { a: ivy.array([12.4, 11.7, 7.25]), b: ivy.array([11.8, 11.8, 4.96]) }
>>> x.random_uniform(high=y, device='cpu', dtype='float64') { a: ivy.array([8.86, 9.24, 6.43]), b: ivy.array([8.95, 10.1, 8.51]) }
>>> z = ivy.Container(a=ivy.zeros((3,)), b=ivy.ones((3,))) >>> x.random_uniform(high=y, device='cpu', dtype='float64', out=z) { a: ivy.array([9.6, 8.24, 3.67]), b: ivy.array([9.29, 11.2, 9.84]) }
>>> x = ivy.Container(a=ivy.array([[9.8,7.6],[6.5,2.3]]), ... b=ivy.array([[0.9,2.4],[7.6,5.4]])) >>> y = ivy.Container(a=ivy.array([[10.9,32.4],[18.7,19.6]]), ... b=ivy.array([[4.3,5.6],[23.4,54.3]])) >>> x.random_uniform(high=y) { a: ivy.array([[10.4, 17.], [9.81, 10.9]]), b: ivy.array([[3.6, 4.31], [18.8, 54.2]]) }
>>> x.random_uniform(high=y, device='cpu') { a: ivy.array([[10.1, 7.93], [7.98, 6.]]), b: ivy.array([[4.28, 4.65], [13.9, 28.9]]) }
>>> x.random_uniform(high=y, dtype='float16') { a: ivy.array([[10.6, 28.], [16.4, 4.92]]), b: ivy.array([[3.61, 4.82], [12.6, 10.2]]) }
>>> x.random_uniform(high=y, device='cpu', dtype='float64') { a: ivy.array([[10.7, 28.4], [9.29, 17.4]]), b: ivy.array([[1.88, 4.94], [17., 9.68]]) }
>>> z = ivy.Container(a=ivy.zeros((2,2)), b=ivy.ones((2,2))) >>> x.random_uniform(high=y, device='cpu', dtype='float64', out=z) { a: ivy.array([[10.4, 29.8], [12.1, 3.9]]), b: ivy.array([[3.79, 5.4], [16.2, 31.7]]) }
- shuffle(axis=0, /, *, seed=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#
ivy.Container instance method variant of ivy.shuffle. This method simply wraps the function, and so the docstring for ivy.shuffle also applies to this method with minimal changes.
- Parameters:
self (
Container
) – Input container. Should have a numeric data type.axis (
Optional
[Union
[int
,Container
]], default:0
) – The axis which input container is shuffled along. Default is 0.seed (
Optional
[Union
[int
,Container
]], default:None
) – A python integer. Used to create a random seed distributionkey_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
],Container
]], default:None
) – The key-chains to apply or not apply the method to. Default isNone
.to_apply (
Union
[bool
,Container
], default:True
) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue
.prune_unapplied (
Union
[bool
,Container
], default:False
) – Whether to prune key_chains for which the function was not applied. Default isFalse
.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.out (
Optional
[Container
], default:None
) – optional output container, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
Container
- Returns:
ret – A container object, shuffled along the first dimension.
Examples
>>> x = ivy.Container(a=ivy.array([5, 2, 9]), ... b=ivy.array([7, 1, 6])) >>> y = ivy.Container.shuffle(x) >>> print(y) { a: ivy.array([9, 5, 2]), b: ivy.array([6, 7, 1]) }
This should have hopefully given you an overview of the random submodule, if you have any questions, please feel free to reach out on our discord!