random_uniform#
- ivy.random_uniform(*, low=0.0, high=1.0, shape=None, device=None, dtype=None, seed=None, out=None)[source]#
Draws samples from a uniform distribution. Samples are uniformly distributed over the half-open interval
[low, high)(includeslow, but excludeshigh). In other words, any value within the given interval is equally likely to be drawn by uniform.- Parameters:
low (
Union[float,NativeArray,Array], 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,NativeArray,Array], 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[Array,Shape,NativeShape]], default:None) – If the given shape is, e.g(m, n, k), thenm * n * ksamples are drawn. Can only be specified whenlowandhighare numeric values, else exception will be raised. Default isNone, where a single value is returned.device (
Optional[Union[Device,NativeDevice]], default:None) – device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc. (Default value = None).dtype (
Optional[Union[Dtype,NativeDtype]], default:None) – output array data type. IfdtypeisNone, the output array data type will be the default floating-point data type. DefaultNoneseed (
Optional[int], default:None) – A python integer. Used to create a random seed distributionout (
Optional[Array], default:None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
- Returns:
ret – Drawn samples from the parameterized uniform distribution.
Examples
>>> ivy.random_uniform() ivy.array(0.26431865)
>>> ivy.random_uniform(shape=3) ivy.array([0.475, 0.878, 0.861])
>>> ivy.random_uniform(shape=(2,3)) ivy.array([[0.929 , 0.545 , 0.789 ], [0.519 , 0.0435, 0.381 ]])
>>> ivy.random_uniform(low=3.0, high=6.0) ivy.array(3.4608004)
>>> ivy.random_uniform(low=1.0, high=2.0, shape=(2,1)) ivy.array([[1.85], [1.81]])
>>> z = ivy.zeros(()) >>> ivy.random_uniform(low=1.0, high=2.0, out=z) ivy.array(1.8458502)
>>> ivy.random_uniform(low=1.0, high=2.0, shape=(2,2), device='cpu') ivy.array([[1.81, 1.8 ], [1.32, 1.43]])
>>> ivy.random_uniform(low=1.0, high=2.0, shape=(2,2), device='cpu', ... dtype='int32') ivy.array([[1, 1], [1, 1]])
>>> z = ivy.zeros((1,2)) >>> ivy.random_uniform(low=1.0, high=2.0, shape=(1,2), device='cpu', ... dtype='float64', out=z) ivy.array([[1.34, 1.02]])
>>> x = ivy.array([4.8, 5.6]) >>> y = ivy.array([9.8, 7.4]) >>> ivy.random_uniform(low=x, high=y) ivy.array([0.475, 0.878])
>>> z = ivy.zeros((2,)) >>> ivy.random_uniform(low=x, high=y, out=z, seed=42) ivy.array([6.67270088, 7.31128597])
>>> ivy.random_uniform(low=x, high=y, device='cpu') ivy.array([6.88, 6.75])
>>> ivy.random_uniform(low=x, high=y, device='cpu', dtype='float64') ivy.array([8.62, 6.47])
>>> z = ivy.zeros((2,)) >>> ivy.random_uniform(low=x, high=y, device='cpu', dtype='float64', out=z) ivy.array([5. , 7.3])
- Array.random_uniform(self, /, *, high=1.0, shape=None, device=None, dtype=None, seed=None, out=None)[source]#
ivy.Array 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 (
Array) – 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,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[Array,Shape,NativeShape]], default:None) – If the given shape is, e.g(m, n, k), thenm * n * ksamples are drawn. Can only be specified whenlowandhighare numeric values, else exception will be raised. Default isNone, where a single value is returned.device (
Optional[Union[Device,NativeDevice]], default:None) – device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc. (Default value = None).dtype (
Optional[Union[Dtype,NativeDtype]], default:None) – output array data type. IfdtypeisNone, the output array data type will be the default floating-point data type. DefaultNoneseed (
Optional[int], default:None) – A python integer. Used to create a random seed distributionout (
Optional[Array], default:None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
Array- Returns:
ret – Drawn samples from the parameterized uniform distribution.
Examples
>>> x = ivy.array([[9.8, 3.4], [5.8, 7.2]]) >>> x.random_uniform(high=10.2) ivy.array([[9.86, 4.89], [7.06, 7.47]])
>>> x.random_uniform(high=10.2, device='cpu') ivy.array([[9.86, 4.89], [7.06, 7.47]])
>>> x.random_uniform(high=14.2, dtype='float16') ivy.array([[9.86, 4.89], [7.06, 7.47]])
>>> x.random_uniform(high=10.8, device='cpu', dtype='float64') ivy.array([[9.86, 4.89], [7.06, 7.47]])
>>> z = ivy.ones((2,2)) >>> x.random_uniform(high=11.2, device='cpu', dtype='float64', out=z) ivy.array([[10.1 , 6.53], [ 7.94, 8.85]])
>>> x = ivy.array([8.7, 9.3]) >>> y = ivy.array([12.8, 14.5]) >>> x.random_uniform(y) ivy.array([12.1, 14. ])
>>> x.random_uniform(high=y, device='cpu') ivy.array([12.1, 14. ])
>>> x.random_uniform(high=y, dtype='float16') ivy.array([12.1, 14. ])
>>> x.random_uniform(high=y, device='cpu', dtype='float64') ivy.array([12.1, 14. ])
>>> z = ivy.ones((2,)) >>> x.random_uniform(high=y, device='cpu', dtype='float64', out=z) ivy.array([12.1, 14. ])
- Container.random_uniform(self, /, *, 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 * ksamples are drawn. Can only be specified whenlowandhighare 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. IfdtypeisNone, the output array data type will be the default floating-point data type. DefaultNoneseed (
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]]) }