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) – The base of the log space. Default is 10.0 (default: 10.0)

  • axis (int) – Axis along which the operation is performed. Relevant only if start or stop are (default: 0) array-like. Default is 0.

  • endpoint (bool) – If True, stop is the last sample. Otherwise, it is not included. Default is (default: True) True.

  • dtype (Optional[Union[Dtype, NativeDtype]]) – The data type of the output tensor. If None, the dtype of on_value is used or if (default: None) 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]]) – device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc. Default is (default: None) None.

  • out (Optional[Array]) – optional output array, for writing the result to. It must have a shape that the (default: None) 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.

Functional 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, 21, 46, 100])
>>> out = ivy.array([0,0,0,0])
>>> ivy.logspace(1, 2, 4, out = out)
>>> print(out)
ivy.array([ 10., 21.5443469, 46.41588834, 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])

>>> 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])      # Broadcasting example
>>> print(ivy.logspace(x, y, 4))
ivy.array([[10., 100.]
           [100., 464.15888336]
           [1000., 2154.43469003]
           [10000., 10000.]])
Array.logspace(self, stop, /, num, *, base=10.0, axis=0, endpoint=True, dtype=None, device=None, out=None)#

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) – The base of the log space. Default is 10.0 (default: 10.0)

  • axis (int) – Axis along which the operation is performed. Relevant only if start or stop (default: 0) are array-like. Default is 0.

  • endpoint (bool) – If True, stop is the last sample. Otherwise, it is not included. Default is (default: True) True.

  • dtype (Optional[Union[Dtype, NativeDtype]]) – The data type of the output tensor. If None, the dtype of on_value is used (default: None) 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]]) – device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc. Default (default: None) is None.

  • out (Optional[Array]) – optional output array, for writing the result to. It must have a shape that (default: None) 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.

Functional 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)#

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 (int) – Number of values to generate.

  • base (float) – The base of the log space. Default is 10.0 (default: 10.0)

  • axis (Optional[int]) – Axis along which the operation is performed. Relevant only if values in (default: None) start or stop containers are array-like. Default is 0.

  • endpoint (bool) – If True, stop is the last sample. Otherwise, it is not included. Default is (default: True) True.

  • dtype (Optional[Union[Dtype, NativeDtype]]) – The data type of the output tensor. If None, the dtype of on_value is used (default: None) 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]]) – device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc. Default (default: None) is None.

  • out (Optional[Container]) – optional output array, for writing the result to. It must have a shape that (default: None) 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.])
        }
}