logspace#
- ivy.logspace(start, stop, /, num, *, base=10.0, axis=0, endpoint=True, dtype=None, device=None, out=None)[source]#
Generate a certain number of evenly-spaced values in log space, in an interval along a given axis.
- Parameters:
start (
Union
[Array
,NativeArray
,float
]) – First value in the range in log space. base ** start is the starting value in the sequence. Can be an array or a float.stop (
Union
[Array
,NativeArray
,float
]) – Last value in the range in log space. base ** stop is the final value in the sequence. Can be an array or a float.num (
int
) – Number of values to generate.base (
float
, default:10.0
) – The base of the log space. Default is 10.0axis (
int
, default:0
) – Axis along which the operation is performed. Relevant only if start or stop are array-like. Default is 0.endpoint (
bool
, default:True
) – If True, stop is the last sample. Otherwise, it is not included. Default is True.dtype (
Optional
[Union
[Dtype
,NativeDtype
]], default:None
) – The data type of the output tensor. If None, the dtype of on_value is used or if that is None, the dtype of off_value is used, or if that is None, defaults to float32. Default is None.device (
Optional
[Union
[Device
,NativeDevice
]], default:None
) – device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc. Default is None.out (
Optional
[Array
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Default is None.
- Return type:
- Returns:
ret – Tensor of evenly-spaced values in log space.
Both the description and the type hints above assumes an array input for simplicity,
but this function is nestable, and therefore also accepts
ivy.Container
instances in place of any of the arguments.
Examples
With float input:
>>> print(ivy.logspace(1, 2, 4)) ivy.array([ 10., 21.5443469, 46.41588834, 100.])
>>> print(ivy.logspace(1, 2, 4, endpoint=False)) ivy.array([10., 17.7827941, 31.6227766, 56.23413252])
>>> print(ivy.logspace(1, 2, 4, dtype= int)) ivy.array([ 10., 10., 10., 100.])
>>> out = ivy.array([0,0,0,0]) >>> ivy.logspace(1, 2, 4, out = out) >>> print(out) ivy.array([ 10, 21, 46, 100])
With
ivy.Array
input: >>> x = ivy.array([1, 2]) >>> y = ivy.array([4, 5]) >>> print(ivy.logspace(x, y, 4)) ivy.array([[1.e+01, 1.e+02],[1.e+02, 1.e+03], [1.e+03, 1.e+04], [1.e+04, 1.e+05])
>>> x = ivy.array([1, 2]) >>> y = ivy.array([4, 5]) >>> print(ivy.logspace(x, y, 4, axis = 1)) ivy.array([[[1.e+01, 1.e+02, 1.e+03, 1.e+04], [1.e+02, 1.e+03, 1.e+04, 1.e+05]]])
>>> x = ivy.array([1, 2]) >>> y = ivy.array([4]) >>> print(ivy.logspace(x, y, 4)) ivy.array([[ 10., 100.], [ 100., 100.], [ 1000., 1000.], [10000., 10000.]])
- Array.logspace(self, stop, /, num, *, base=10.0, axis=0, endpoint=True, dtype=None, device=None, out=None)[source]#
ivy.Array instance method variant of ivy.logspace. This method simply wraps the function, and so the docstring for ivy.logspace also applies to this method with minimal changes.
- Parameters:
self (
Array
) – First value in the range in log space. base ** start is the starting value in the sequence. Can be an array or a float.stop (
Union
[Array
,NativeArray
,float
]) – Last value in the range in log space. base ** stop is the final value in the sequence. Can be an array or a float.num (
int
) – Number of values to generate.base (
float
, default:10.0
) – The base of the log space. Default is 10.0axis (
int
, default:0
) – Axis along which the operation is performed. Relevant only if start or stop are array-like. Default is 0.endpoint (
bool
, default:True
) – If True, stop is the last sample. Otherwise, it is not included. Default is True.dtype (
Optional
[Union
[Dtype
,NativeDtype
]], default:None
) – The data type of the output tensor. If None, the dtype of on_value is used or if that is None, the dtype of off_value is used, or if that is None, defaults to float32. Default is None.device (
Optional
[Union
[Device
,NativeDevice
]], default:None
) – device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc. Default is None.out (
Optional
[Array
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Default is None.
- Return type:
Array
- Returns:
ret – Tensor of evenly-spaced values in log space.
Both the description and the type hints above assumes an array input for
simplicity, but this function is *nestable, and therefore also accepts*
ivy.Container
instances in place of any of the arguments.
Examples
With float input:
>>> x = ivy.array([1, 2]) >>> y = ivy.array([4, 5]) >>> x.logspace(y, 4) ivy.array([[1.e+01, 1.e+02], [1.e+02, 1.e+03], [1.e+03, 1.e+04], [1.e+04, 1.e+05])
>>> x.logspace(y, 4, axis = 1) ivy.array([[[1.e+01, 1.e+02, 1.e+03, 1.e+04], [1.e+02, 1.e+03, 1.e+04, 1.e+05]]])
>>> x = ivy.array([1, 2]) >>> y = ivy.array([4]) # Broadcasting example >>> x.logspace(y, 4) ivy.array([[10., 100.] [100., 464.15888336] [1000., 2154.43469003] [10000., 10000.]])
- Container.logspace(self, stop, /, num, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, base=10.0, axis=None, endpoint=True, dtype=None, device=None, out=None)[source]#
ivy.Container instance method variant of ivy.logspace. This method simply wraps the function, and so the docstring for ivy.logspace also applies to this method with minimal changes.
- Parameters:
self (
Container
) – Container for first value in the range in log space.stop (
Union
[Array
,NativeArray
,float
,Container
]) – Container for last value in the range in log space.num (
Union
[int
,Container
]) – Number of values to generate.base (
Union
[float
,Container
], default:10.0
) – The base of the log space. Default is 10.0axis (
Optional
[Union
[int
,Container
]], default:None
) – Axis along which the operation is performed. Relevant only if values in start or stop containers are array-like. Default is 0.endpoint (
Union
[bool
,Container
], default:True
) – If True, stop is the last sample. Otherwise, it is not included. Default is True.dtype (
Optional
[Union
[Dtype
,NativeDtype
,Container
]], default:None
) – The data type of the output tensor. If None, the dtype of on_value is used or if that is None, the dtype of off_value is used, or if that is None, defaults to float32. Default is None.device (
Optional
[Union
[Device
,NativeDevice
,Container
]], default:None
) – device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc. Default is None.out (
Optional
[Container
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Default is None.
- Return type:
Container
- Returns:
ret – a container having the same shape as
self
and filled with tensor of evenly-spaced values in log space.
Examples
>>> x = ivy.Container(a = 1, b = 0) >>> y = ivy.Container(a = 4, b = 1) >>> z = x.logspace(y, 4) { a: ivy.array([10., 100., 1000., 10000.]), b: ivy.array([ 1., 2.15443469, 4.64158883, 10.]) }
>>> x = ivy.Container(a = 1, b = 0) >>> y = ivy.Container(a = 4, b = 1) >>> z = ivy.logspace(x, y, 4) { a: ivy.array([10., 100., 1000., 10000.]), b: ivy.array([ 1., 2.15443469, 4.64158883, 10.]) }
>>> u = ivy.Container(c = 0, d = 0) >>> v = ivy.Container(c = 1, d = 2) >>> x = ivy.Container(a = 1, b = u) >>> y = ivy.Container(a = 4, b = v) >>> z = x.logspace(y, 4) { a: ivy.array([10., 100., 1000., 10000.]), b: { c: ivy.array([ 1., 2.15443469, 4.64158883, 10.]) d: ivy.array([ 1., 4.64158883, 21.5443469, 100.]) } }